Skip to content

Commit b1164bd

Browse files
committed
Update deps
1 parent cf2e420 commit b1164bd

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

bower.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@
2626
"output"
2727
],
2828
"dependencies": {
29-
"purescript-arrays": "^1.0.0",
30-
"purescript-either": "^1.0.0",
31-
"purescript-foreign": "^1.0.0",
32-
"purescript-foldable-traversable": "^1.0.0",
33-
"purescript-transformers": "^1.0.0",
34-
"purescript-aff": "^1.0.0",
35-
"purescript-integers": "^1.0.0",
36-
"purescript-datetime": "^1.0.0",
37-
"purescript-unsafe-coerce": "^1.0.0",
38-
"purescript-nullable": "^1.0.1"
29+
"purescript-arrays": "^3.0.0",
30+
"purescript-either": "^2.0.0",
31+
"purescript-foreign": "^3.0.0",
32+
"purescript-foldable-traversable": "^2.0.0",
33+
"purescript-transformers": "^2.0.0",
34+
"purescript-aff": "^2.0.0",
35+
"purescript-integers": "^2.0.0",
36+
"purescript-datetime": "^2.0.0",
37+
"purescript-unsafe-coerce": "^2.0.0",
38+
"purescript-nullable": "^2.0.0"
3939
},
4040
"devDependencies": {
41-
"purescript-spec": "~0.8.0",
42-
"purescript-generics": "~1.0.0"
41+
"purescript-spec": "git://github.com/anttih/purescript-spec#psc-0.10-updates",
42+
"purescript-generics": "^3.0.0",
43+
"purescript-js-date": "^3.0.0"
4344
}
4445
}

src/Database/Postgres.purs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ module Database.Postgres
1818

1919
import Prelude
2020
import Control.Monad.Eff (Eff)
21-
import Data.Either (either)
21+
import Data.Either (Either, either)
2222
import Data.Function.Uncurried (Fn2(), runFn2)
2323
import Data.Array ((!!))
24-
import Data.Foreign (Foreign, ForeignError)
24+
import Data.Foreign (Foreign, MultipleErrors)
2525
import Data.Foreign.Class (class IsForeign, read)
2626
import Data.Maybe (Maybe(Just, Nothing), maybe)
27+
import Control.Monad.Except (runExcept)
2728
import Control.Monad.Aff (Aff, finally)
2829
import Control.Monad.Eff.Class (liftEff)
2930
import Control.Monad.Eff.Exception (error)
@@ -75,41 +76,41 @@ query :: forall eff a
7576
=> Query a -> Array SqlValue -> Client -> Aff (db :: DB | eff) (Array a)
7677
query (Query sql) params client = do
7778
rows <- runQuery sql params client
78-
either liftError pure (sequence $ read <$> rows)
79+
either liftError pure (runExcept (sequence $ read <$> rows))
7980

8081
-- | Just like `query` but does not make any param replacement
8182
query_ :: forall eff a. (IsForeign a) => Query a -> Client -> Aff (db :: DB | eff) (Array a)
8283
query_ (Query sql) client = do
8384
rows <- runQuery_ sql client
84-
either liftError pure (sequence $ read <$> rows)
85+
either liftError pure (runExcept (sequence $ read <$> rows))
8586

8687
-- | Runs a query and returns the first row, if any
8788
queryOne :: forall eff a
8889
. (IsForeign a)
8990
=> Query a -> Array SqlValue -> Client -> Aff (db :: DB | eff) (Maybe a)
9091
queryOne (Query sql) params client = do
9192
rows <- runQuery sql params client
92-
maybe (pure Nothing) (either liftError (pure <<< Just)) $ read <$> (rows !! 0)
93+
maybe (pure Nothing) (either liftError (pure <<< Just)) (readFirst rows)
9394

9495
-- | Just like `queryOne` but does not make any param replacement
9596
queryOne_ :: forall eff a. (IsForeign a) => Query a -> Client -> Aff (db :: DB | eff) (Maybe a)
9697
queryOne_ (Query sql) client = do
9798
rows <- runQuery_ sql client
98-
maybe (pure Nothing) (either liftError (pure <<< Just)) $ read <$> (rows !! 0)
99+
maybe (pure Nothing) (either liftError (pure <<< Just)) (readFirst rows)
99100

100101
-- | Runs a query and returns a single value, if any.
101102
queryValue :: forall eff a
102103
. (IsForeign a)
103104
=> Query a -> Array SqlValue -> Client -> Aff (db :: DB | eff) (Maybe a)
104105
queryValue (Query sql) params client = do
105106
val <- runQueryValue sql params client
106-
pure $ either (const Nothing) Just (read val)
107+
pure $ either (const Nothing) Just (runExcept (read val))
107108

108109
-- | Just like `queryValue` but does not make any param replacement
109110
queryValue_ :: forall eff a. (IsForeign a) => Query a -> Client -> Aff (db :: DB | eff) (Maybe a)
110111
queryValue_ (Query sql) client = do
111112
val <- runQueryValue_ sql client
112-
either liftError (pure <<< Just) $ read val
113+
either liftError (pure <<< Just) $ runExcept (read val)
113114

114115
-- | Connects to the database, calls the provided function with the client
115116
-- | and returns the results.
@@ -129,8 +130,11 @@ withClient :: forall eff a
129130
-> Aff (db :: DB | eff) a
130131
withClient info p = runFn2 _withClient (mkConnectionString info) p
131132

132-
liftError :: forall e a. ForeignError -> Aff e a
133-
liftError err = throwError $ error (show err)
133+
readFirst :: forall a. IsForeign a => Array Foreign -> Maybe (Either MultipleErrors a)
134+
readFirst rows = runExcept <<< read <$> (rows !! 0)
135+
136+
liftError :: forall e a. MultipleErrors -> Aff e a
137+
liftError errs = throwError $ error (show errs)
134138

135139
foreign import connect' :: forall eff. String -> Aff (db :: DB | eff) Client
136140

src/Database/Postgres/Transaction.purs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Database.Postgres.Transaction where
22

33
import Prelude
4-
import Control.Apply ((*>))
54
import Control.Monad.Aff (Aff, attempt)
65
import Control.Monad.Error.Class (throwError)
76
import Data.Either (either)

0 commit comments

Comments
 (0)