Skip to content

Commit a406a5b

Browse files
committed
Fix query to lift ForeignErrors to Aff errors
1 parent b277700 commit a406a5b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

MODULE.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,27 @@ data DB :: !
2424
```
2525

2626

27+
#### `ConnectionString`
28+
29+
``` purescript
30+
type ConnectionString = String
31+
```
32+
33+
2734
#### `ConnectionInfo`
2835

2936
``` purescript
3037
type ConnectionInfo = { password :: String, user :: String, port :: Number, db :: String, host :: String }
3138
```
3239

3340

41+
#### `mkConnectionString`
42+
43+
``` purescript
44+
mkConnectionString :: ConnectionInfo -> ConnectionString
45+
```
46+
47+
3448
#### `connect`
3549

3650
``` purescript
@@ -58,7 +72,7 @@ Runs a query and returns nothing
5872
#### `query`
5973

6074
``` purescript
61-
query :: forall eff a p. (IsForeign a) => Query a -> [SqlValue] -> Client -> Aff (db :: DB | eff) [F a]
75+
query :: forall eff a p. (IsForeign a) => Query a -> [SqlValue] -> Client -> Aff (db :: DB | eff) [a]
6276
```
6377

6478
Runs a query and returns all results.

src/Database/Postgres.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ execute_ (Query sql) client = void $ runQuery_ sql client
7070
-- | Runs a query and returns all results.
7171
query :: forall eff a p
7272
. (IsForeign a)
73-
=> Query a -> [SqlValue] -> Client -> Aff (db :: DB | eff) [F a]
73+
=> Query a -> [SqlValue] -> Client -> Aff (db :: DB | eff) [a]
7474
query (Query sql) params client = do
7575
rows <- runQuery sql params client
76-
pure $ read <$> rows
76+
either liftError pure (sequence $ read <$> rows)
7777

7878
-- | Just like `query` but does not make any param replacement
7979
query_ :: forall eff a. (IsForeign a) => Query a -> Client -> Aff (db :: DB | eff) [a]

0 commit comments

Comments
 (0)