Skip to content
This repository
Browse code

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
  • Loading branch information...
commit f6de08c189277f330c6f5412567a2545cfa27902 1 parent 012770e
Leon P Smith authored

Showing 1 changed file with 14 additions and 9 deletions. Show diff stats Hide diff stats

  1. +14 9 src/Database/PostgreSQL/Simple/FromField.hs
23 src/Database/PostgreSQL/Simple/FromField.hs
@@ -290,15 +290,20 @@ instance FromField Date where
290 290
291 291 ff :: BuiltinType -> String -> (B8.ByteString -> Either String a)
292 292 -> 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
302 307 {-# INLINE ff #-}
303 308
304 309 instance (FromField a, FromField b) => FromField (Either a b) where

0 comments on commit f6de08c

Please sign in to comment.
Something went wrong with that request. Please try again.