git.iko.soy/typeable/postgresql-simple
on master help sign in
Refactor conversion function

This gets rid of an (incorrect) warning message, eliminates some dead code in the generated code, and keeps things under 80 characters

commitf6de08c189277f330c6f5412567a2545cfa27902 authorLeon P Smith <leon@melding-monads.com> dateSun 27 Jan 2013, 16:12 (14 years ago) parent012770e
1 file changed+14−9
src/Database/PostgreSQL/Simple/FromField.hs+14−9
src/Database/PostgreSQL/Simple/FromField.hs+14−9
@@ -290,15 +290,20 @@ instance FromField Date where
290290
291291ff :: BuiltinType -> String -> (B8.ByteString -> Either String a)
292292 -> Field -> Maybe B8.ByteString -> Ok a
293−ff pgType hsType parse f mstr
294− | typeOid f /= builtin2oid pgType
295− = left (Incompatible (B8.unpack (typename f)) (tableOid f) (maybe "" B8.unpack (name f)) hsType "")
296− | Nothing <- mstr
297− = left (UnexpectedNull (B8.unpack (typename f)) (tableOid f) (maybe "" B8.unpack (name f)) hsType "")
298− | Just str <- mstr
299− = case parse str of
300− Left msg -> left (ConversionFailed (B8.unpack (typename f)) (tableOid f) (maybe "" B8.unpack (name f)) hsType msg)
301− Right val -> return val
293+ff pgType hsType parse f mstr =
294+ if typeOid f /= builtin2oid pgType
295+ then err Incompatible ""
296+ else case mstr of
297+ Nothing -> err UnexpectedNull ""
298+ Just str -> case parse str of
299+ Left msg -> err ConversionFailed msg
300+ Right val -> return val
301+ where
302+ err errC msg = left $ errC (B8.unpack (typename f))
303+ (tableOid f)
304+ (maybe "" B8.unpack (name f))
305+ hsType
306+ msg
302307{-# INLINE ff #-}
303308
304309instance (FromField a, FromField b) => FromField (Either a b) where