| Copyright | 2015 Dylan Simon |
|---|---|
| Safe Haskell | None |
| Language | Haskell98 |
Database.PostgreSQL.Typed.Types
Description
Classes to support type inference, value encoding/decoding, and instances to support built-in PostgreSQL types.
- type OID = Word32
- data PGValue
- = PGNullValue
- | PGTextValue {
- pgTextValue :: PGTextValue
- | PGBinaryValue {
- pgBinaryValue :: PGBinaryValue
- type PGValues = [PGValue]
- data PGTypeID t = PGTypeProxy
- data PGTypeEnv = PGTypeEnv {}
- unknownPGTypeEnv :: PGTypeEnv
- newtype PGName = PGName {
- pgNameBytes :: [Word8]
- pgNameBS :: PGName -> ByteString
- pgNameString :: PGName -> String
- newtype PGRecord = PGRecord [Maybe PGTextValue]
- class (KnownSymbol t, PGParameter t (PGVal t), PGColumn t (PGVal t)) => PGType t where
- class PGType t => PGParameter t a where
- class PGType t => PGColumn t a where
- class PGType t => PGStringType t
- class PGType t => PGRecordType t
- pgEncodeParameter :: PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> PGValue
- pgEscapeParameter :: PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> ByteString
- pgDecodeColumn :: PGColumn t (Maybe a) => PGTypeEnv -> PGTypeID t -> PGValue -> Maybe a
- pgDecodeColumnNotNull :: PGColumn t a => PGTypeEnv -> PGTypeID t -> PGValue -> a
- pgQuote :: ByteString -> ByteString
- pgDQuote :: [Char] -> ByteString -> Builder
- parsePGDQuote :: Bool -> [Char] -> (ByteString -> Bool) -> Parser (Maybe ByteString)
- buildPGValue :: Builder -> ByteString
Basic types
A value passed to or from PostgreSQL in raw format.
Constructors
| PGNullValue | |
| PGTextValue | The standard text encoding format (also used for unknown formats) |
Fields
| |
| PGBinaryValue | Special binary-encoded data. Not supported in all cases. |
Fields
| |
A proxy type for PostgreSQL types. The type argument should be an (internal) name of a database type, as per format_type(OID) (usually the same as \dT+).
When the type's namespace (schema) is not in search_path, this will be explicitly qualified, so you should be sure to have a consistent search_path for all database connections.
The underlying Symbol should be considered a lifted PGName.
Constructors
| PGTypeProxy |
Parameters that affect how marshalling happens. Currenly we force all other relevant parameters at connect time. Nothing values represent unknown.
Constructors
| PGTypeEnv | |
Fields
| |
A PostgreSQL literal identifier, generally corresponding to the "name" type (63-byte strings), but as it would be entered in a query, so may include double-quoting for special characters or schema-qualification.
Constructors
| PGName | |
Fields
| |
pgNameBS :: PGName -> ByteString #
The literal identifier as used in a query.
pgNameString :: PGName -> String #
Reverses the IsString instantce.
Generic class of composite (row or record) types.
Instances
| PGRecordType t => PGColumn t PGRecord # | |
| PGRecordType t => PGParameter t PGRecord # | |
Marshalling classes
class (KnownSymbol t, PGParameter t (PGVal t), PGColumn t (PGVal t)) => PGType t where #
A valid PostgreSQL type, its metadata, and corresponding Haskell representation.
For conversion the other way (from Haskell type to PostgreSQL), see PGRep.
Unfortunately any instances of this will be orphans.
Associated Types
The default, native Haskell representation of this type, which should be as close as possible to the PostgreSQL representation.
Methods
pgTypeName :: PGTypeID t -> PGName #
The string name of this type: specialized version of symbolVal.
pgBinaryColumn :: PGTypeEnv -> PGTypeID t -> Bool #
Does this type support binary decoding?
If so, pgDecodeBinary must be implemented for every PGColumn instance of this type.
Instances
| PGType "\"char\"" # | |
| PGType "any" # | |
| PGType "bigint" # | |
| PGType "boolean" # | |
| PGType "bpchar" # | |
| PGType "bytea" # | |
| PGType "character varying" # | |
| PGType "date" # | |
| PGType "double precision" # | |
| PGType "integer" # | |
| PGType "interval" # | |
| PGType "json" # | |
| PGType "jsonb" # | |
| PGType "name" # | |
| PGType "numeric" # | |
| PGType "oid" # | |
| PGType "real" # | |
| PGType "record" # | |
| PGType "smallint" # | |
| PGType "text" # | |
| PGType "time with time zone" # | |
| PGType "time without time zone" # | |
| PGType "timestamp with time zone" # | |
| PGType "timestamp without time zone" # | |
| PGType "uuid" # | |
| PGType "void" # | |
class PGType t => PGParameter t a where #
A PGParameter t a instance describes how to encode a PostgreSQL type t from a.
Minimal complete definition
Methods
pgEncode :: PGTypeID t -> a -> PGTextValue #
Encode a value to a PostgreSQL text representation.
pgLiteral :: PGTypeID t -> a -> ByteString #
Encode a value to a (quoted) literal value for use in SQL statements.
Defaults to a quoted version of pgEncode
pgEncodeValue :: PGTypeEnv -> PGTypeID t -> a -> PGValue #
Encode a value to a PostgreSQL representation. Defaults to the text representation by pgEncode
Instances
class PGType t => PGColumn t a where #
A PGColumn t a instance describes how te decode a PostgreSQL type t to a.
Minimal complete definition
Methods
pgDecode :: PGTypeID t -> PGTextValue -> a #
Decode the PostgreSQL text representation into a value.
pgDecodeBinary :: PGTypeEnv -> PGTypeID t -> PGBinaryValue -> a #
Decode the PostgreSQL binary representation into a value.
Only needs to be implemented if pgBinaryColumn is true.
pgDecodeValue :: PGTypeEnv -> PGTypeID t -> PGValue -> a #
Instances
| PGRecordType t => PGColumn t PGRecord # | |
| PGStringType t => PGColumn t Text # | |
| PGStringType t => PGColumn t Text # | |
| PGStringType t => PGColumn t ByteString # | |
| PGStringType t => PGColumn t PGName # | |
| PGStringType t => PGColumn t ByteString # | |
| PGStringType t => PGColumn t String # | |
| PGType t => PGColumn t PGValue # | |
| PGColumn "\"char\"" Char # | |
| PGColumn "\"char\"" Word8 # | |
| PGColumn "bigint" Int64 # | |
| PGColumn "boolean" Bool # | |
| PGColumn "bytea" ByteString # | |
| PGColumn "bytea" ByteString # | |
| PGColumn "cidr" PGInet # | |
| PGColumn "date" Day # | |
| PGColumn "double precision" Double # | |
| PGColumn "inet" PGInet # | |
| PGColumn "integer" Int32 # | |
| PGColumn "interval" DiffTime # | Representation of DiffTime as interval. PostgreSQL stores months and days separately in intervals, but DiffTime does not. We collapse all interval fields into seconds |
| PGColumn "json" Value # | |
| PGColumn "jsonb" Value # | |
| PGColumn "numeric" Rational # | High-precision representation of Rational as numeric. Unfortunately, numeric has an NaN, while Rational does not. NaN numeric values will produce exceptions. |
| PGColumn "numeric" Scientific # | |
| PGColumn "oid" OID # | |
| PGColumn "real" Double # | |
| PGColumn "real" Float # | |
| PGColumn "smallint" Int16 # | |
| PGColumn "time without time zone" TimeOfDay # | |
| PGColumn "timestamp with time zone" UTCTime # | |
| PGColumn "timestamp without time zone" LocalTime # | |
| PGColumn "uuid" UUID # | |
| PGColumn "void" () # | |
| PGColumn t a => PGColumn t (Maybe a) # | |
| (PGRangeType t, PGColumn (PGSubType t) a) => PGColumn t (Range a) # | |
| PGColumn "time with time zone" (TimeOfDay, TimeZone) # | |
class PGType t => PGStringType t #
Instances
| PGStringType "bpchar" # | |
| PGStringType "character varying" # | |
| PGStringType "name" # | |
| PGStringType "text" # | |
class PGType t => PGRecordType t #
Instances
| PGRecordType "record" # | The generic anonymous record type, as created by |
Marshalling interface
pgEncodeParameter :: PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> PGValue #
Final parameter encoding function used when a (nullable) parameter is passed to a prepared query.
pgEscapeParameter :: PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> ByteString #
Final parameter escaping function used when a (nullable) parameter is passed to be substituted into a simple query.
pgDecodeColumn :: PGColumn t (Maybe a) => PGTypeEnv -> PGTypeID t -> PGValue -> Maybe a #
Final column decoding function used for a nullable result value.
pgDecodeColumnNotNull :: PGColumn t a => PGTypeEnv -> PGTypeID t -> PGValue -> a #
Final column decoding function used for a non-nullable result value.
Conversion utilities
pgQuote :: ByteString -> ByteString #
Produce a SQL string literal by wrapping (and escaping) a string with single quotes.
pgDQuote :: [Char] -> ByteString -> Builder #
Double-quote a value if it's "", "null", or contains any whitespace, '"', '\', or the characters given in the first argument. Checking all these things may not be worth it. We could just double-quote everything.
parsePGDQuote :: Bool -> [Char] -> (ByteString -> Bool) -> Parser (Maybe ByteString) #
Parse double-quoted values ala pgDQuote.
buildPGValue :: Builder -> ByteString #
Shorthand for toStrict . toLazyByteString