Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Database/SQLite/Simple/FromField.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Database.SQLite.Simple.FromField
, returnError
) where

import Control.Applicative (Applicative, (<$>), pure)
import Control.Applicative (Applicative, (<$>), (<|>), pure)
import Control.Exception (SomeException(..), Exception)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as B
Expand Down Expand Up @@ -102,6 +102,9 @@ instance (FromField a) => FromField (Maybe a) where
fromField (Field SQLNull _) = pure Nothing
fromField f = Just <$> fromField f

instance (FromField a, FromField b) => FromField (Either a b) where
fromField f = (Left <$> fromField f) <|> (Right <$> fromField f)

instance FromField Null where
fromField (Field SQLNull _) = pure Null
fromField f = returnError ConversionFailed f "data is not null"
Expand Down
5 changes: 5 additions & 0 deletions Database/SQLite/Simple/ToField.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ instance (ToField a) => ToField (Maybe a) where
toField (Just a) = toField a
{-# INLINE toField #-}

instance (ToField a, ToField b) => ToField (Either a b) where
toField (Left a) = toField a
toField (Right b) = toField b
{-# INLINE toField #-}

instance ToField Null where
toField _ = Base.SQLNull
{-# INLINE toField #-}
Expand Down