git.iko.soy/typeable/postgresql-simple
on master help sign in
Added the FieldParser synonym and renamed fieldWith
da0481bLeon P Smith
src/Database/PostgreSQL/Simple/FromField.hs+4−1
@@ -27,6 +27,7 @@
27module Database.PostgreSQL.Simple.FromField
27module Database.PostgreSQL.Simple.FromField
28 (
28 (
29 FromField(..)
29 FromField(..)
30+ , FieldParser
30 , ResultError(..)
31 , ResultError(..)
31 , returnError
32 , returnError
32
33
@@ -95,9 +96,11 @@ instance Exception ResultError
95left :: Exception a => a -> Ok b
96left :: Exception a => a -> Ok b
96left = Errors . (:[]) . SomeException
97left = Errors . (:[]) . SomeException
97
98
99+type FieldParser a = Field -> Maybe ByteString -> Ok a
100+
98-- | A type that may be converted from a SQL type.
101-- | A type that may be converted from a SQL type.
99class FromField a where
102class FromField a where
100− fromField :: Field -> Maybe ByteString -> Ok a
103+ fromField :: FieldParser a
101 -- ^ Convert a SQL value to a Haskell value.
104 -- ^ Convert a SQL value to a Haskell value.
102 --
105 --
103 -- Returns a list of exceptions if the conversion fails. In the case of
106 -- Returns a list of exceptions if the conversion fails. In the case of
src/Database/PostgreSQL/Simple/FromRow.hs+4−4
@@ -20,7 +20,7 @@ module Database.PostgreSQL.Simple.FromRow
20 ( FromRow(..)
20 ( FromRow(..)
21 , RowParser
21 , RowParser
22 , field
22 , field
23− , field'
23+ , fieldWith
24 , numFieldsRemaining
24 , numFieldsRemaining
25 ) where
25 ) where
26
26
@@ -65,8 +65,8 @@ import Data.Vector ((!))
65class FromRow a where
65class FromRow a where
66 fromRow :: RowParser a
66 fromRow :: RowParser a
67
67
68−field' :: (Field -> Maybe ByteString -> Ok a) -> RowParser a
68+fieldWith :: FieldParser a -> RowParser a
69−field' fieldP = RP $ do
69+fieldWith fieldP = RP $ do
70 let unCol (PQ.Col x) = fromIntegral x :: Int
70 let unCol (PQ.Col x) = fromIntegral x :: Int
71 Row{..} <- ask
71 Row{..} <- ask
72 column <- lift get
72 column <- lift get
@@ -91,7 +91,7 @@ field' fieldP = RP $ do
91 lift (lift (fieldP field (getvalue result row column)))
91 lift (lift (fieldP field (getvalue result row column)))
92
92
93field :: FromField a => RowParser a
93field :: FromField a => RowParser a
94−field = field' fromField
94+field = fieldWith fromField
95
95
96ellipsis :: ByteString -> ByteString
96ellipsis :: ByteString -> ByteString
97ellipsis bs
97ellipsis bs