Copyright | 2015 Dylan Simon |
---|---|
Safe Haskell | None |
Language | Haskell98 |
Automatic (dynamic) marshalling of PostgreSQL values based on Haskell types (not SQL statements). This is intended for direct construction of queries and query data, bypassing the normal SQL type inference.
- class PGType t => PGRep t a | a -> t where
- pgLiteralString :: PGRep t a => a -> String
- pgSafeLiteral :: PGRep t a => a -> ByteString
- pgSafeLiteralString :: PGRep t a => a -> String
- pgSubstituteLiterals :: String -> ExpQ
Documentation
class PGType t => PGRep t a | a -> t where Source #
Represents canonical/default PostgreSQL representation for various Haskell types, allowing convenient type-driven marshalling.
pgTypeOf :: a -> PGTypeName t Source #
pgEncodeRep :: a -> PGValue Source #
pgEncodeRep :: PGParameter t a => a -> PGValue Source #
pgLiteralRep :: a -> ByteString Source #
Produce a literal value for interpolation in a SQL statement. Using pgSafeLiteral
is usually safer as it includes type cast.
pgLiteralRep :: PGParameter t a => a -> ByteString Source #
Produce a literal value for interpolation in a SQL statement. Using pgSafeLiteral
is usually safer as it includes type cast.
pgDecodeRep :: PGValue -> a Source #
pgDecodeRep :: PGColumn t a => PGValue -> a Source #
PGRep "\"char\"" Char Source # | |
PGRep "bigint" Int64 Source # | |
PGRep "boolean" Bool Source # | |
PGRep "date" Day Source # | |
PGRep "double precision" Double Source # | |
PGRep "integer" Int32 Source # | |
PGRep "interval" DiffTime Source # | |
PGRep "numeric" Rational Source # | |
PGRep "numeric" Scientific Source # | |
PGRep "oid" OID Source # | |
PGRep "real" Float Source # | |
PGRep "smallint" Int16 Source # | |
PGRep "text" String Source # | |
PGRep "text" ByteString Source # | |
PGRep "text" Text Source # | |
PGRep "time without time zone" TimeOfDay Source # | |
PGRep "timestamp with time zone" UTCTime Source # | |
PGRep "timestamp without time zone" LocalTime Source # | |
PGRep "uuid" UUID Source # | |
PGRep t a => PGRep t (Maybe a) Source # | |
PGRep "time with time zone" (TimeOfDay, TimeZone) Source # | |
pgLiteralString :: PGRep t a => a -> String Source #
Produce a raw SQL literal from a value. Using pgSafeLiteral
is usually safer when interpolating in a SQL statement.
pgSafeLiteral :: PGRep t a => a -> ByteString Source #
Produce a safely type-cast literal value for interpolation in a SQL statement, e.g., "'123'::integer".
pgSafeLiteralString :: PGRep t a => a -> String Source #
Identical to
but more efficient.unpack
. pgSafeLiteral
pgSubstituteLiterals :: String -> ExpQ Source #
Create an expression that literally substitutes each instance of ${expr}
for the result of pgSafeLiteral expr
, producing a lazy ByteString
.
This lets you do safe, type-driven literal substitution into SQL fragments without needing a full query, bypassing placeholder inference and any prepared queries, for example when using pgSimpleQuery
or pgSimpleQueries_
.
Unlike most other TH functions, this does not require any database connection.