git.iko.soy/typeable/postgresql-simple
on master help sign in
Move some of FromField to TypeInfo.Static
commit4b60ad710b99266f8afff2ae437a8b328fcae0af authorLeon P Smith <leon@melding-monads.com> dateMon 25 Mar 2013, 16:19 (14 years ago) parent67a1f9b
1 file changed+16−15
src/Database/PostgreSQL/Simple/FromField.hs+16−15
src/Database/PostgreSQL/Simple/FromField.hs+16−15
@@ -108,6 +108,7 @@ import Database.PostgreSQL.Simple.Compat
108108import Database.PostgreSQL.Simple.Ok
109109import Database.PostgreSQL.Simple.Types (Binary(..), Null(..))
110110import Database.PostgreSQL.Simple.TypeInfo as TypeInfo
111+import qualified Database.PostgreSQL.Simple.TypeInfo.Static as TypeInfo
111112import Database.PostgreSQL.Simple.Time
112113import Database.PostgreSQL.Simple.Arrays as Arrays
113114import qualified Database.PostgreSQL.LibPQ as PQ
@@ -234,7 +235,7 @@ instance FromField Null where
234235
235236instance FromField Bool where
236237 fromField f bs
237− | typeOid f /= builtin2oid Bool = returnError Incompatible f ""
238+ | typeOid f /= typoid (TypeInfo.bool) = returnError Incompatible f ""
238239 | bs == Nothing = returnError UnexpectedNull f ""
239240 | bs == Just "t" = pure True
240241 | bs == Just "f" = pure False
@@ -271,7 +272,7 @@ unBinary :: Binary t -> t
271272unBinary (Binary x) = x
272273
273274instance FromField SB.ByteString where
274− fromField f dat = if typeOid f == builtin2oid ByteA
275+ fromField f dat = if typeOid f == typoid TypeInfo.bytea
275276 then unBinary <$> fromField f dat
276277 else doFromField f okText' (pure . B.copy) dat
277278
@@ -306,36 +307,36 @@ instance FromField [Char] where
306307 fromField f dat = ST.unpack <$> fromField f dat
307308
308309instance FromField UTCTime where
309− fromField = ff TimestampTZ "UTCTime" parseUTCTime
310+ fromField = ff TypeInfo.timestamptz "UTCTime" parseUTCTime
310311
311312instance FromField ZonedTime where
312− fromField = ff TimestampTZ "ZonedTime" parseZonedTime
313+ fromField = ff TypeInfo.timestamptz "ZonedTime" parseZonedTime
313314
314315instance FromField LocalTime where
315− fromField = ff Timestamp "LocalTime" parseLocalTime
316+ fromField = ff TypeInfo.timestamp "LocalTime" parseLocalTime
316317
317318instance FromField Day where
318− fromField = ff Date "Day" parseDay
319+ fromField = ff TypeInfo.date "Day" parseDay
319320
320321instance FromField TimeOfDay where
321− fromField = ff Time "TimeOfDay" parseTimeOfDay
322+ fromField = ff TypeInfo.time "TimeOfDay" parseTimeOfDay
322323
323324instance FromField UTCTimestamp where
324− fromField = ff TimestampTZ "UTCTimestamp" parseUTCTimestamp
325+ fromField = ff TypeInfo.timestamptz "UTCTimestamp" parseUTCTimestamp
325326
326327instance FromField ZonedTimestamp where
327− fromField = ff TimestampTZ "ZonedTimestamp" parseZonedTimestamp
328+ fromField = ff TypeInfo.timestamptz "ZonedTimestamp" parseZonedTimestamp
328329
329330instance FromField LocalTimestamp where
330− fromField = ff Timestamp "LocalTimestamp" parseLocalTimestamp
331+ fromField = ff TypeInfo.timestamp "LocalTimestamp" parseLocalTimestamp
331332
332333instance FromField Date where
333− fromField = ff Date "Date" parseDate
334+ fromField = ff TypeInfo.date "Date" parseDate
334335
335−ff :: BuiltinType -> String -> (B8.ByteString -> Either String a)
336+ff :: TypeInfo -> String -> (B8.ByteString -> Either String a)
336337 -> Field -> Maybe B8.ByteString -> Conversion a
337338ff pgType hsType parse f mstr =
338− if typeOid f /= builtin2oid pgType
339+ if typeOid f /= typoid pgType
339340 then err Incompatible ""
340341 else case mstr of
341342 Nothing -> err UnexpectedNull ""
@@ -366,10 +367,10 @@ instance (FromField a, Typeable a) => FromField (Vector a) where
366367 Just dat -> do
367368 case parseOnly (fromArray info f) dat of
368369 Left err -> returnError ConversionFailed f err
369− Right conv -> V.fromList <$> conv
370+ Right conv -> V.fromList <$> conv
370371 _ -> returnError Incompatible f ""
371372
372−fromArray :: (FromField a)
373+fromArray :: (FromField a)
373374 => TypeInfo -> Field -> Parser (Conversion [a])
374375fromArray typeInfo f = sequence . (parseIt <$>) <$> array delim
375376 where