git.iko.soy/typeable/postgresql-simple
on master help sign in
Add FromField instance for Char
commit0eb44385b669fc5b789c7fec549054830c89531e authorLeon P Smith <leon@melding-monads.com> dateTue 26 Mar 2013, 21:10 (14 years ago) parentdb14cf8
1 file changed+10
src/Database/PostgreSQL/Simple/FromField.hs+10
src/Database/PostgreSQL/Simple/FromField.hs+10
@@ -241,6 +241,16 @@ instance FromField Bool where
241241 | bs == Just "f" = pure False
242242 | otherwise = returnError ConversionFailed f ""
243243
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+
244254instance FromField Int16 where
245255 fromField = atto ok16 $ signed decimal
246256