Skip to content

Fix query to lift ForeignErrors to Aff errors #7

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
May 4, 2015
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
16 changes: 15 additions & 1 deletion MODULE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@ data DB :: !
```


#### `ConnectionString`

``` purescript
type ConnectionString = String
```


#### `ConnectionInfo`

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


#### `mkConnectionString`

``` purescript
mkConnectionString :: ConnectionInfo -> ConnectionString
```


#### `connect`

``` purescript
Expand Down Expand Up @@ -58,7 +72,7 @@ Runs a query and returns nothing
#### `query`

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

Runs a query and returns all results.
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Postgres.purs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ execute_ (Query sql) client = void $ runQuery_ sql client
-- | Runs a query and returns all results.
query :: forall eff a p
. (IsForeign a)
=> Query a -> [SqlValue] -> Client -> Aff (db :: DB | eff) [F a]
=> Query a -> [SqlValue] -> Client -> Aff (db :: DB | eff) [a]
query (Query sql) params client = do
rows <- runQuery sql params client
pure $ read <$> rows
either liftError pure (sequence $ read <$> rows)

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