Add Maybe support

This commit is contained in:
rightfold 2017-01-12 19:23:43 +01:00
parent b9c7dbedea
commit a8c34f37f9

View File

@ -26,7 +26,8 @@ import Control.Monad.Except (runExcept)
import Data.Array (head)
import Data.ByteString (ByteString)
import Data.Either (Either(..))
import Data.Foreign (Foreign, readArray, readChar, readInt, readString, toForeign, unsafeFromForeign)
import Data.Foreign (Foreign, isNull, readArray, readChar, readInt, readString, toForeign, unsafeFromForeign)
import Data.Foreign.Null (writeNull)
import Data.List (List)
import Data.List as List
import Data.Maybe (fromJust, Maybe(..))
@ -151,6 +152,14 @@ instance fromSQLValueByteString :: FromSQLValue ByteString where
| unsafeIsBuffer x = Just $ unsafeFromForeign x
| otherwise = Nothing
instance toSQLValueMaybe :: (ToSQLValue a) => ToSQLValue (Maybe a) where
toSQLValue Nothing = writeNull
toSQLValue (Just x) = toSQLValue x
instance fromSQLValueMaybe :: (FromSQLValue a) => FromSQLValue (Maybe a) where
fromSQLValue x | isNull x = Just Nothing
| otherwise = Just <$> fromSQLValue x
foreign import unsafeIsBuffer :: a. a -> Boolean
-- | Create a new connection pool.