git.iko.soy/typeable/postgresql-simple
on master help sign in
Code for "instance Result Null"
commitaa4487306e92247dc012c6986758b531fd3da98a authorLeon P Smith <leon@melding-monads.com> dateFri 30 Dec 2011, 13:30 (15 years ago) parent4e912e3
1 file changed+5−1
src/Database/PostgreSQL/Simple/Result.hs+5−1
src/Database/PostgreSQL/Simple/Result.hs+5−1
@@ -48,7 +48,7 @@ import Data.Word (Word64)
4848import Database.PostgreSQL.Simple.Internal
4949import Database.PostgreSQL.Simple.Field (Field(..), RawResult(..))
5050import Database.PostgreSQL.Simple.BuiltinTypes
51−import Database.PostgreSQL.Simple.Types (Binary(..))
51+import Database.PostgreSQL.Simple.Types (Binary(..), Null(..))
5252import qualified Database.PostgreSQL.LibPQ as PQ
5353import System.IO.Unsafe (unsafePerformIO)
5454import System.Locale (defaultTimeLocale)
@@ -98,6 +98,10 @@ instance (Result a) => Result (Maybe a) where
9898 convert _ Nothing = pure Nothing
9999 convert f bs = Just <$> convert f bs
100100
101+instance Result Null where
102+ convert _ Nothing = pure Null
103+ convert f (Just _) = returnError ConversionFailed f "data is not null"
104+
101105instance Result Bool where
102106 convert f bs
103107 | typeOid f /= builtin2oid Bool = returnError Incompatible f ""