Copyright | 2015 Dylan Simon |
---|---|
Safe Haskell | None |
Language | Haskell98 |
Support functions for compile-time PostgreSQL connection and state management. You can use these to build your own Template Haskell functions using the PostgreSQL connection.
- getTPGDatabase :: IO PGDatabase
- withTPGConnection :: (PGConnection -> IO a) -> IO a
- useTPGDatabase :: PGDatabase -> DecsQ
- reloadTPGTypes :: DecsQ
- data TPGValueInfo = TPGValueInfo {
- tpgValueName :: String
- tpgValueTypeOID :: !OID
- tpgValueType :: TPGType
- tpgValueBinary :: Bool
- tpgValueNullable :: Bool
- tpgDescribe :: String -> [String] -> Bool -> Q ([TPGValueInfo], [TPGValueInfo])
- tpgTypeEncoder :: Bool -> TPGValueInfo -> Name -> Name -> Exp
- tpgTypeDecoder :: TPGValueInfo -> Name -> Name -> Exp
Documentation
getTPGDatabase :: IO PGDatabase Source
Generate a PGDatabase
based on the environment variables:
TPG_HOST
(localhost); TPG_SOCK
or TPG_PORT
(5432); TPG_DB
or user; TPG_USER
or USER
(postgres); TPG_PASS
()
withTPGConnection :: (PGConnection -> IO a) -> IO a Source
Run an action using the Template Haskell PostgreSQL connection.
useTPGDatabase :: PGDatabase -> DecsQ Source
Specify an alternative database to use during compilation.
This lets you override the default connection parameters that are based on TPG environment variables.
This should be called as a top-level declaration and produces no code.
It uses pgReconnect
so is safe to call multiple times with the same database.
reloadTPGTypes :: DecsQ Source
Force reloading of all types from the database. This may be needed if you make structural changes to the database during compile-time.
data TPGValueInfo Source
TPGValueInfo | |
|
tpgDescribe :: String -> [String] -> Bool -> Q ([TPGValueInfo], [TPGValueInfo]) Source
A type-aware wrapper to pgDescribe
tpgTypeEncoder :: Bool -> TPGValueInfo -> Name -> Name -> Exp Source
TH expression to encode a PGParameter
value to a Maybe
ByteString
.
tpgTypeDecoder :: TPGValueInfo -> Name -> Name -> Exp Source
TH expression to decode a Maybe
ByteString
to a (Maybe
) PGColumn
value.