diff --git a/bower.json b/bower.json index 2e2a510..f2ebe90 100644 --- a/bower.json +++ b/bower.json @@ -2,19 +2,19 @@ "name": "purescript-postgresql-client", "license": "BSD-3-Clause", "dependencies": { - "purescript-prelude": "^2.1.0", - "purescript-transformers": "^2.0.2", - "purescript-lists": "^3.2.1", - "purescript-foreign": "^3.0.1", - "purescript-tuples": "^3.0.0", - "purescript-aff": "^2.0.2", - "purescript-either": "^2.0.0", - "purescript-maybe": "^2.0.1", - "purescript-foldable-traversable": "^2.0.0", - "purescript-newtype": "^1.1.0", - "purescript-bytestrings": "^2.3.0", - "purescript-arrays": "^3.1.0", - "purescript-datetime": "^2.0.0" + "purescript-prelude": "^3.0.0", + "purescript-transformers": "^3.1.0", + "purescript-lists": "^4.0.1", + "purescript-foreign": "^4.0.0", + "purescript-tuples": "^4.0.0", + "purescript-aff": "^3.0.0", + "purescript-either": "^3.0.0", + "purescript-maybe": "^3.0.0", + "purescript-foldable-traversable": "^3.0.0", + "purescript-newtype": "^2.0.0", + "purescript-bytestrings": "^3.0.1", + "purescript-arrays": "^4.0.1", + "purescript-datetime": "^3.0.0" }, "repository": { "type": "git", diff --git a/src/Database/PostgreSQL.js b/src/Database/PostgreSQL.js index 3b4c03f..01c1e65 100644 --- a/src/Database/PostgreSQL.js +++ b/src/Database/PostgreSQL.js @@ -59,3 +59,5 @@ exports.instantToString = function(i) { exports.unsafeIsBuffer = function(x) { return x instanceof Buffer; }; + +exports['null'] = null; diff --git a/src/Database/PostgreSQL.purs b/src/Database/PostgreSQL.purs index 51273b8..e6fc19f 100644 --- a/src/Database/PostgreSQL.purs +++ b/src/Database/PostgreSQL.purs @@ -21,6 +21,7 @@ module Database.PostgreSQL ) where import Control.Monad.Aff (Aff) +import Control.Monad.Eff (kind Effect) import Control.Monad.Eff.Exception (error) import Control.Monad.Error.Class (catchError, throwError) import Control.Monad.Except (runExcept) @@ -30,7 +31,6 @@ import Data.ByteString (ByteString) import Data.DateTime.Instant (Instant) import Data.Either (Either(..)) import Data.Foreign (Foreign, isNull, readArray, readBoolean, readChar, readInt, readNumber, readString, toForeign, unsafeFromForeign) -import Data.Foreign.Null (writeNull) import Data.List (List) import Data.List as List import Data.Maybe (Maybe(..)) @@ -40,7 +40,7 @@ import Data.Tuple (fst, Tuple) import Data.Tuple.Nested ((/\)) import Prelude -foreign import data POSTGRESQL :: ! +foreign import data POSTGRESQL :: Effect -- | PostgreSQL connection pool configuration. type PoolConfiguration = @@ -53,11 +53,13 @@ type PoolConfiguration = , idleTimeoutMillis :: Int } +foreign import null :: Foreign + -- | PostgreSQL connection pool. -foreign import data Pool :: * +foreign import data Pool :: Type -- | PostgreSQL connection. -foreign import data Connection :: * +foreign import data Connection :: Type -- | PostgreSQL query with parameter (`$1`, `$2`, …) and return types. newtype Query i o = Query String @@ -143,7 +145,7 @@ instance toSQLValueInstant :: ToSQLValue Instant where toSQLValue = instantToString instance toSQLValueMaybe :: (ToSQLValue a) => ToSQLValue (Maybe a) where - toSQLValue Nothing = writeNull + toSQLValue Nothing = null toSQLValue (Just x) = toSQLValue x instance fromSQLValueMaybe :: (FromSQLValue a) => FromSQLValue (Maybe a) where @@ -196,7 +198,8 @@ execute conn (Query sql) values = -- | Execute a PostgreSQL query and return its results. query :: ∀ i o eff - . (ToSQLRow i, FromSQLRow o) + . ToSQLRow i + => FromSQLRow o => Connection -> Query i o -> i @@ -209,7 +212,8 @@ query conn (Query sql) values = scalar :: ∀ i o eff - . (ToSQLRow i, FromSQLValue o) + . ToSQLRow i + => FromSQLValue o => Connection -> Query i (Tuple o Unit) -> i