Add FromField Char
This commit is contained in:
@@ -9,6 +9,7 @@ module Database.PostgreSQL.Opium.FromField
|
||||
|
||||
import Data.Attoparsec.Text
|
||||
( Parser
|
||||
, anyChar
|
||||
, choice
|
||||
, decimal
|
||||
, double
|
||||
@@ -38,14 +39,22 @@ class FromField a where
|
||||
validOid :: Proxy a -> Oid -> Bool
|
||||
parseField :: Parser a
|
||||
|
||||
-- | See https://www.postgresql.org/docs/current/datatype-character.html.
|
||||
instance FromField Text where
|
||||
validOid _ = 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
|
||||
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
|
||||
parseField = anyChar
|
||||
|
||||
instance FromField Int where
|
||||
validOid _ = Oid.smallint \/ Oid.integer \/ Oid.bigint
|
||||
parseField = signed decimal
|
||||
|
||||
Reference in New Issue
Block a user