diff --git a/bower.json b/bower.json index 7c9841c..88288bf 100644 --- a/bower.json +++ b/bower.json @@ -12,7 +12,8 @@ "purescript-either": "^2.0.0", "purescript-maybe": "^2.0.1", "purescript-foldable-traversable": "^2.0.0", - "purescript-newtype": "^1.1.0" + "purescript-newtype": "^1.1.0", + "purescript-bytestrings": "^0.0.3" }, "repository": { "type": "git", diff --git a/src/Database/PostgreSQL.js b/src/Database/PostgreSQL.js index 31915af..f4e2501 100644 --- a/src/Database/PostgreSQL.js +++ b/src/Database/PostgreSQL.js @@ -47,3 +47,7 @@ exports._query = function(client) { }; }; }; + +exports.unsafeIsBuffer = function(x) { + return x instanceof Buffer; +}; diff --git a/src/Database/PostgreSQL.purs b/src/Database/PostgreSQL.purs index 4937b18..4c49748 100644 --- a/src/Database/PostgreSQL.purs +++ b/src/Database/PostgreSQL.purs @@ -22,8 +22,9 @@ module Database.PostgreSQL import Control.Monad.Aff (Aff) import Control.Monad.Error.Class (catchError, throwError) import Control.Monad.Except (runExcept) +import Data.ByteString (ByteString) import Data.Either (Either(..)) -import Data.Foreign (Foreign, readArray, readChar, readString, toForeign) +import Data.Foreign (Foreign, readArray, readChar, readString, toForeign, unsafeFromForeign) import Data.List (List) import Data.List as List import Data.Maybe (fromJust, Maybe(..)) @@ -134,6 +135,16 @@ instance fromSQLValueArray :: (FromSQLValue a) => FromSQLValue (Array a) where instance fromSQLValueList :: (FromSQLValue a) => FromSQLValue (List a) where fromSQLValue = map List.fromFoldable <<< traverse fromSQLValue <=< fromRight <<< runExcept <<< readArray +instance toSQLValueByteString :: ToSQLValue ByteString where + toSQLValue = toForeign + +instance fromSQLValueByteString :: FromSQLValue ByteString where + fromSQLValue x + | unsafeIsBuffer x = Just $ unsafeFromForeign x + | otherwise = Nothing + +foreign import unsafeIsBuffer :: ∀ a. a -> Boolean + -- | Create a new connection pool. foreign import newPool :: ∀ eff