Skip to content

Add IsSqlValue class to Arrays of IsSqlValues #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ instance isSqlValueMaybe :: (IsSqlValue a) => IsSqlValue (Maybe a)
```


#### `isSqlValueArray`

``` purescript
instance isSqlValueArray :: (IsSqlValue a) => IsSqlValue (Array a)
```



## Module Database.Postgres.Transaction

Expand Down
3 changes: 3 additions & 0 deletions src/Database/Postgres/SqlValue.purs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ instance isSqlValueInt :: IsSqlValue Int where
instance isSqlValueMaybe :: (IsSqlValue a) => IsSqlValue (Maybe a) where
toSql = unsafeCoerce <<< toNullable <<< (toSql <$> _)

instance isSqlValueArray :: (IsSqlValue a) => IsSqlValue (Array a) where
toSql = unsafeCoerce <<< map toSql

instance isSqlValueDateTime :: IsSqlValue DateTime where
toSql = toSql <<< format
where
Expand Down
11 changes: 11 additions & 0 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ main = run [consoleReporter] do
) dt
liftEff $ end pool

describe "sql arrays as parameters" $
it "can be passed as a SqlValue" do
pool <- liftEff $ mkPool connectionInfo
withClient pool \c -> do
execute_ (Query "delete from artist") c
execute_ (Query "insert into artist values ('Zed Leppelin', 1967)") c
execute_ (Query "insert into artist values ('Led Zeppelin', 1968)") c
execute_ (Query "insert into artist values ('Deep Purple', 1969)") c
artists <- query (Query "select * from artist where year = any ($1)" :: Query Artist) [toSql [1968, 1969]] c
length artists `shouldEqual` 2
liftEff $ end pool

describe "transactions" do
it "does not commit after an error inside a transation" do
Expand Down