Copyright | 2015 Dylan Simon |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Database.PostgreSQL.Typed.Types
Description
Classes to support type inference, value encoding/decoding, and instances to support built-in PostgreSQL types.
Synopsis
- type OID = Word32
- data PGValue
- = PGNullValue
- | PGTextValue {
- pgTextValue :: PGTextValue
- | PGBinaryValue {
- pgBinaryValue :: PGBinaryValue
- type PGValues = [PGValue]
- data PGTypeID (t :: Symbol) = 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 :: Symbol) where
- type PGVal (t :: Symbol)
- pgTypeName :: PGTypeID t -> PGName
- pgBinaryColumn :: PGTypeEnv -> PGTypeID t -> Bool
- class PGType t => PGParameter (t :: Symbol) a where
- pgEncode :: PGTypeID t -> a -> PGTextValue
- pgLiteral :: PGTypeID t -> a -> ByteString
- pgEncodeValue :: PGTypeEnv -> PGTypeID t -> a -> PGValue
- class PGType t => PGColumn (t :: Symbol) a where
- pgDecode :: PGTypeID t -> PGTextValue -> a
- pgDecodeBinary :: PGTypeEnv -> PGTypeID t -> PGBinaryValue -> a
- pgDecodeValue :: PGTypeEnv -> PGTypeID t -> PGValue -> a
- class PGType t => PGStringType (t :: Symbol)
- class PGType t => PGRecordType (t :: Symbol)
- pgEncodeParameter :: forall (t :: Symbol) a. PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> PGValue
- pgEscapeParameter :: forall (t :: Symbol) a. PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> ByteString
- pgDecodeColumn :: forall (t :: Symbol) a. PGColumn t (Maybe a) => PGTypeEnv -> PGTypeID t -> PGValue -> Maybe a
- pgDecodeColumnNotNull :: forall (t :: Symbol) a. PGColumn t a => PGTypeEnv -> PGTypeID t -> PGValue -> a
- pgQuote :: ByteString -> ByteString
- pgDQuote :: ByteString -> Builder
- pgDQuoteFrom :: [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
|
Instances
Show PGValue Source # | |
Eq PGValue Source # | |
PGQuery ByteString PGValues Source # | |
Defined in Database.PostgreSQL.Typed.Query Methods pgRunQuery :: PGConnection -> ByteString -> IO (Int, [PGValues]) Source # unsafeModifyQuery :: ByteString -> (ByteString -> ByteString) -> ByteString Source # getQueryString :: PGTypeEnv -> ByteString -> ByteString Source # | |
PGType t => PGColumn t PGValue Source # | |
PGParameter "any" PGValue Source # | |
IsString (PGSimpleQuery PGValues) Source # | |
Defined in Database.PostgreSQL.Typed.Query Methods fromString :: String -> PGSimpleQuery PGValues # |
type PGValues = [PGValue] Source #
A list of (nullable) data values, e.g. a single row or query parameters.
data PGTypeID (t :: Symbol) Source #
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
|
Instances
Data PGName Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PGName -> c PGName # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PGName # toConstr :: PGName -> Constr # dataTypeOf :: PGName -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PGName) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PGName) # gmapT :: (forall b. Data b => b -> b) -> PGName -> PGName # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PGName -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PGName -> r # gmapQ :: (forall d. Data d => d -> u) -> PGName -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> PGName -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> PGName -> m PGName # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PGName -> m PGName # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PGName -> m PGName # | |||||
IsString PGName Source # | Applies utf-8 encoding. | ||||
Defined in Database.PostgreSQL.Typed.Types Methods fromString :: String -> PGName # | |||||
Show PGName Source # | Unquoted | ||||
Eq PGName Source # | |||||
Ord PGName Source # | |||||
PGRep PGName Source # | |||||
Defined in Database.PostgreSQL.Typed.Dynamic Associated Types
| |||||
PGStringType t => PGColumn t PGName Source # | |||||
PGStringType t => PGParameter t PGName Source # | |||||
type PGRepType PGName Source # | |||||
Defined in Database.PostgreSQL.Typed.Dynamic |
pgNameBS :: PGName -> ByteString Source #
The literal identifier as used in a query.
Generic class of composite (row or record) types.
Instances
PGRecordType t => PGColumn t PGRecord Source # | |
PGRecordType t => PGParameter t PGRecord Source # | |
Marshalling classes
class (KnownSymbol t, PGParameter t (PGVal t), PGColumn t (PGVal t)) => PGType (t :: Symbol) where Source #
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.
Minimal complete definition
Nothing
Associated Types
type PGVal (t :: Symbol) Source #
The default, native Haskell representation of this type, which should be as close as possible to the PostgreSQL representation.
Methods
pgTypeName :: PGTypeID t -> PGName Source #
The string name of this type: specialized version of symbolVal
.
pgBinaryColumn :: PGTypeEnv -> PGTypeID t -> Bool Source #
Does this type support binary decoding?
If so, pgDecodeBinary
must be implemented for every PGColumn
instance of this type.
Instances
PGType "\"char\"" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "\"char\"" => PGType "\"char\"[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "abstime" => PGType "abstime[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "aclitem" => PGType "aclitem[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "any" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "bigint" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "bigint" => PGType "bigint[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "bit" => PGType "bit[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "boolean" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "boolean" => PGType "boolean[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "box" => PGType "box[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "bpchar" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "bpchar" => PGType "bpchar[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "bytea" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "bytea" => PGType "bytea[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "character varying" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "character varying" => PGType "character varying[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "cid" => PGType "cid[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "cidr" Source # | |||||
Defined in Database.PostgreSQL.Typed.Inet Associated Types
| |||||
PGType "cidr" => PGType "cidr[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "circle" => PGType "circle[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "cstring" => PGType "cstring[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "date" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "date" => PGType "date[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "daterange" Source # | |||||
Defined in Database.PostgreSQL.Typed.Range Associated Types
| |||||
PGType "daterange" => PGType "daterange[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "double precision" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "double precision" => PGType "double precision[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "gtsvector" => PGType "gtsvector[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "inet" Source # | |||||
Defined in Database.PostgreSQL.Typed.Inet Associated Types
| |||||
PGType "inet" => PGType "inet[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "int2vector" => PGType "int2vector[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "int4range" Source # | |||||
Defined in Database.PostgreSQL.Typed.Range Associated Types
| |||||
PGType "int4range" => PGType "int4range[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "int8range" Source # | |||||
Defined in Database.PostgreSQL.Typed.Range Associated Types
| |||||
PGType "int8range" => PGType "int8range[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "integer" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "integer" => PGType "integer[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "interval" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "interval" => PGType "interval[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "json" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "json" => PGType "json[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "jsonb" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "line" => PGType "line[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "lseg" => PGType "lseg[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "macaddr" => PGType "macaddr[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "money" => PGType "money[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "name" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "name" => PGType "name[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "numeric" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "numeric" => PGType "numeric[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "numrange" Source # | |||||
Defined in Database.PostgreSQL.Typed.Range Associated Types
| |||||
PGType "numrange" => PGType "numrange[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "oid" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "oid" => PGType "oid[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "oidvector" => PGType "oidvector[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "path" => PGType "path[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "point" => PGType "point[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "polygon" => PGType "polygon[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "real" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "real" => PGType "real[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "record" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "record" => PGType "record[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "refcursor" => PGType "refcursor[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "regclass" => PGType "regclass[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "regconfig" => PGType "regconfig[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "regdictionary" => PGType "regdictionary[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "regoper" => PGType "regoper[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "regoperator" => PGType "regoperator[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "regproc" => PGType "regproc[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "regprocedure" => PGType "regprocedure[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "regtype" => PGType "regtype[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "reltime" => PGType "reltime[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "smallint" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "smallint" => PGType "smallint[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "text" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "text" => PGType "text[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "tid" => PGType "tid[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "time with time zone" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "time with time zone" => PGType "time with time zone[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "time without time zone" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "time without time zone" => PGType "time without time zone[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "timestamp with time zone" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "timestamp with time zone" => PGType "timestamp with time zone[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "timestamp without time zone" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "timestamp without time zone" => PGType "timestamp without time zone[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "tinterval" => PGType "tinterval[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "tsquery" => PGType "tsquery[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "tsrange" Source # | |||||
Defined in Database.PostgreSQL.Typed.Range Associated Types
| |||||
PGType "tsrange" => PGType "tsrange[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "tstzrange" Source # | |||||
Defined in Database.PostgreSQL.Typed.Range Associated Types
| |||||
PGType "tstzrange" => PGType "tstzrange[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "tsvector" => PGType "tsvector[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "txid_snapshot" => PGType "txid_snapshot[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "uuid" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "uuid" => PGType "uuid[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "varbit" => PGType "varbit[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "void" Source # | |||||
Defined in Database.PostgreSQL.Typed.Types Associated Types
| |||||
PGType "xid" => PGType "xid[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
| |||||
PGType "xml" => PGType "xml[]" Source # | |||||
Defined in Database.PostgreSQL.Typed.Array Associated Types
|
class PGType t => PGParameter (t :: Symbol) a where Source #
A PGParameter t a
instance describes how to encode a PostgreSQL type t
from a
.
Minimal complete definition
Methods
pgEncode :: PGTypeID t -> a -> PGTextValue Source #
Encode a value to a PostgreSQL text representation.
pgLiteral :: PGTypeID t -> a -> ByteString Source #
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 Source #
Encode a value to a PostgreSQL representation. Defaults to the text representation by pgEncode
Instances
class PGType t => PGColumn (t :: Symbol) a where Source #
A PGColumn t a
instance describes how te decode a PostgreSQL type t
to a
.
Minimal complete definition
Methods
pgDecode :: PGTypeID t -> PGTextValue -> a Source #
Decode the PostgreSQL text representation into a value.
pgDecodeBinary :: PGTypeEnv -> PGTypeID t -> PGBinaryValue -> a Source #
Decode the PostgreSQL binary representation into a value.
Only needs to be implemented if pgBinaryColumn
is true.
pgDecodeValue :: PGTypeEnv -> PGTypeID t -> PGValue -> a Source #
Instances
class PGType t => PGStringType (t :: Symbol) Source #
Instances
PGStringType "bpchar" Source # | |
Defined in Database.PostgreSQL.Typed.Types | |
PGStringType "character varying" Source # | |
Defined in Database.PostgreSQL.Typed.Types | |
PGStringType "name" Source # | |
Defined in Database.PostgreSQL.Typed.Types | |
PGStringType "text" Source # | |
Defined in Database.PostgreSQL.Typed.Types |
class PGType t => PGRecordType (t :: Symbol) Source #
Instances
PGRecordType "record" Source # | The generic anonymous record type, as created by |
Defined in Database.PostgreSQL.Typed.Types |
Marshalling interface
pgEncodeParameter :: forall (t :: Symbol) a. PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> PGValue Source #
Final parameter encoding function used when a (nullable) parameter is passed to a prepared query.
pgEscapeParameter :: forall (t :: Symbol) a. PGParameter t a => PGTypeEnv -> PGTypeID t -> a -> ByteString Source #
Final parameter escaping function used when a (nullable) parameter is passed to be substituted into a simple query.
pgDecodeColumn :: forall (t :: Symbol) a. PGColumn t (Maybe a) => PGTypeEnv -> PGTypeID t -> PGValue -> Maybe a Source #
Final column decoding function used for a nullable result value.
pgDecodeColumnNotNull :: forall (t :: Symbol) a. PGColumn t a => PGTypeEnv -> PGTypeID t -> PGValue -> a Source #
Final column decoding function used for a non-nullable result value.
Conversion utilities
pgQuote :: ByteString -> ByteString Source #
Produce a SQL string literal by wrapping (and escaping) a string with single quotes.
pgDQuote :: ByteString -> Builder Source #
Double-quote a value (e.g., as an identifier). Does not properly handle unicode escaping (yet).
pgDQuoteFrom :: [Char] -> ByteString -> Builder Source #
Double-quote a value if it's "", "null", or contains any whitespace, '"', '\', or the characters given in the first argument.
parsePGDQuote :: Bool -> [Char] -> (ByteString -> Bool) -> Parser (Maybe ByteString) Source #
Parse double-quoted values ala pgDQuote
.
buildPGValue :: Builder -> ByteString Source #
Shorthand for toStrict
. toLazyByteString