Support Instant serialization

This commit is contained in:
rightfold 2017-01-30 11:12:55 +01:00
parent 4589da021b
commit c14897d6ed
3 changed files with 11 additions and 1 deletions

View File

@ -14,7 +14,8 @@
"purescript-foldable-traversable": "^2.0.0",
"purescript-newtype": "^1.1.0",
"purescript-bytestrings": "^0.0.3",
"purescript-arrays": "^3.1.0"
"purescript-arrays": "^3.1.0",
"purescript-datetime": "^2.0.0"
},
"repository": {
"type": "git",

View File

@ -52,6 +52,10 @@ exports._query = function(client) {
};
};
exports.instantToString = function(i) {
return new Date(i).toUTCString();
};
exports.unsafeIsBuffer = function(x) {
return x instanceof Buffer;
};

View File

@ -25,6 +25,7 @@ import Control.Monad.Error.Class (catchError, throwError)
import Control.Monad.Except (runExcept)
import Data.Array (head)
import Data.ByteString (ByteString)
import Data.DateTime.Instant (Instant)
import Data.Either (Either(..))
import Data.Foreign (Foreign, isNull, readArray, readChar, readInt, readString, toForeign, unsafeFromForeign)
import Data.Foreign.Null (writeNull)
@ -143,6 +144,9 @@ instance fromSQLValueByteString :: FromSQLValue ByteString where
| unsafeIsBuffer x = Just $ unsafeFromForeign x
| otherwise = Nothing
instance toSQLValueInstant :: ToSQLValue Instant where
toSQLValue = instantToString
instance toSQLValueMaybe :: (ToSQLValue a) => ToSQLValue (Maybe a) where
toSQLValue Nothing = writeNull
toSQLValue (Just x) = toSQLValue x
@ -151,6 +155,7 @@ instance fromSQLValueMaybe :: (FromSQLValue a) => FromSQLValue (Maybe a) where
fromSQLValue x | isNull x = Just Nothing
| otherwise = Just <$> fromSQLValue x
foreign import instantToString :: Instant -> Foreign
foreign import unsafeIsBuffer :: a. a -> Boolean
-- | Create a new connection pool.