git.iko.soy/typeable/postgresql-simple
on master help sign in
Add FromField instance for Char
0eb4438Leon P Smith
src/Database/PostgreSQL/Simple/FromField.hs+10
@@ -241,6 +241,16 @@ instance FromField Bool where
241 | bs == Just "f" = pure False
241 | bs == Just "f" = pure False
242 | otherwise = returnError ConversionFailed f ""
242 | otherwise = returnError ConversionFailed f ""
243
243
244+instance FromField Char where
245+ fromField f bs =
246+ if typeOid f /= typoid (TypeInfo.char)
247+ then returnError Incompatible f ""
248+ else case bs of
249+ Nothing -> returnError UnexpectedNull f ""
250+ Just bs -> if B.length bs /= 1
251+ then returnError ConversionFailed f "length not 1"
252+ else return $! (B.head bs)
253+
244instance FromField Int16 where
254instance FromField Int16 where
245 fromField = atto ok16 $ signed decimal
255 fromField = atto ok16 $ signed decimal
246
256