Add ByteString support

Fixes #5.
This commit is contained in:
rightfold 2017-01-07 15:30:31 +01:00
parent 53d1c6630a
commit ada69d008a
3 changed files with 18 additions and 2 deletions

View File

@ -12,7 +12,8 @@
"purescript-either": "^2.0.0", "purescript-either": "^2.0.0",
"purescript-maybe": "^2.0.1", "purescript-maybe": "^2.0.1",
"purescript-foldable-traversable": "^2.0.0", "purescript-foldable-traversable": "^2.0.0",
"purescript-newtype": "^1.1.0" "purescript-newtype": "^1.1.0",
"purescript-bytestrings": "^0.0.3"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -47,3 +47,7 @@ exports._query = function(client) {
}; };
}; };
}; };
exports.unsafeIsBuffer = function(x) {
return x instanceof Buffer;
};

View File

@ -22,8 +22,9 @@ module Database.PostgreSQL
import Control.Monad.Aff (Aff) import Control.Monad.Aff (Aff)
import Control.Monad.Error.Class (catchError, throwError) import Control.Monad.Error.Class (catchError, throwError)
import Control.Monad.Except (runExcept) import Control.Monad.Except (runExcept)
import Data.ByteString (ByteString)
import Data.Either (Either(..)) 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 (List)
import Data.List as List import Data.List as List
import Data.Maybe (fromJust, Maybe(..)) 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 instance fromSQLValueList :: (FromSQLValue a) => FromSQLValue (List a) where
fromSQLValue = map List.fromFoldable <<< traverse fromSQLValue <=< fromRight <<< runExcept <<< readArray 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. -- | Create a new connection pool.
foreign import newPool foreign import newPool
:: eff :: eff