Add FromField Integer
This commit is contained in:
@@ -41,22 +41,28 @@ class FromField a where
|
||||
|
||||
-- | See https://www.postgresql.org/docs/current/datatype-character.html.
|
||||
instance FromField Text where
|
||||
validOid _ = Oid.text \/ Oid.character \/ Oid.characterVarying
|
||||
validOid Proxy = Oid.text \/ Oid.character \/ Oid.characterVarying
|
||||
parseField = takeText
|
||||
|
||||
-- | See https://www.postgresql.org/docs/current/datatype-character.html.
|
||||
instance FromField String where
|
||||
validOid _ = validOid @Text Proxy
|
||||
validOid Proxy = validOid @Text Proxy
|
||||
parseField = Text.unpack <$> parseField
|
||||
|
||||
-- | See https://www.postgresql.org/docs/current/datatype-character.html.
|
||||
-- This instance accepts all character types but fails to decode fields that are not exactly one character.
|
||||
instance FromField Char where
|
||||
validOid _ = validOid @Text Proxy
|
||||
validOid Proxy = validOid @Text Proxy
|
||||
parseField = anyChar
|
||||
|
||||
-- | See https://www.postgresql.org/docs/current/datatype-numeric.html.
|
||||
instance FromField Int where
|
||||
validOid _ = Oid.smallint \/ Oid.integer \/ Oid.bigint
|
||||
validOid Proxy = Oid.smallint \/ Oid.integer \/ Oid.bigint
|
||||
parseField = signed decimal
|
||||
|
||||
-- | See https://www.postgresql.org/docs/current/datatype-numeric.html.
|
||||
instance FromField Integer where
|
||||
validOid Proxy = Oid.smallint \/ Oid.integer \/ Oid.bigint
|
||||
parseField = signed decimal
|
||||
|
||||
doubleParser :: Parser Double
|
||||
@@ -70,11 +76,11 @@ doubleParser = choice
|
||||
infinity = 1 / 0
|
||||
|
||||
instance FromField Float where
|
||||
validOid _ = Oid.real
|
||||
validOid Proxy = Oid.real
|
||||
parseField = fmap double2Float doubleParser
|
||||
|
||||
instance FromField Double where
|
||||
validOid _ = Oid.real \/ Oid.doublePrecision
|
||||
validOid Proxy = Oid.real \/ Oid.doublePrecision
|
||||
parseField = doubleParser
|
||||
|
||||
boolParser :: Parser Bool
|
||||
@@ -85,5 +91,5 @@ boolParser = choice
|
||||
|
||||
-- | See https://www.postgresql.org/docs/current/datatype-boolean.html.
|
||||
instance FromField Bool where
|
||||
validOid _ = Oid.boolean
|
||||
validOid Proxy = Oid.boolean
|
||||
parseField = boolParser
|
||||
|
||||
Reference in New Issue
Block a user