Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data PostgresConf = PostgresConf {}
- newtype PGPool = PGPool {}
- createPGPool :: PostgresConf -> IO PGPool
- type PGCallback = Connection -> IO ()
- createPGPoolWithCallback :: PostgresConf -> PGCallback -> IO PGPool
- pingPGPool :: PGPool -> IO ()
- withPGPool :: (MonadReader site m, MonadBaseControl IO m) => (site -> PGPool) -> (Connection -> m a) -> m a
- withPGPoolPrim :: MonadBaseControl IO m => m PGPool -> (Connection -> m a) -> m a
Types
data PostgresConf Source
Configuration parsed from json or yaml file, or obtained by any other way. Example configuration yml is:
database: "dbname" host: "127.0.0.1" # optional port: "5432" # optional user: "dbuser" password: "pass" poolsize: "10" # optional maximum connections in pool pooltimeout: "60" # optional minimum connection lifetime poolstripes: "1" # optional count of stripes in pool
PostgresConf | |
|
Connection pool. Must be created from settings using
createPGPool
Pool creation
createPGPool :: PostgresConf -> IO PGPool Source
Create pool from parsed configuration
type PGCallback = Connection -> IO () Source
createPGPoolWithCallback Source
:: PostgresConf | connection data |
-> PGCallback | callback action, can be used for performing arbitrary action on connection |
-> IO PGPool |
Create pool from parsed configuration, which enables to fire a callback after creating each connection.
pingPGPool :: PGPool -> IO () Source
Force to create at least one connection in pool. Usefull to check connection settings at program start time
Helpers for postgresql-query
withPGPool :: (MonadReader site m, MonadBaseControl IO m) => (site -> PGPool) -> (Connection -> m a) -> m a Source
Combinator for simple implementation of withPGConnection
method
from package postgresql-query. Typical usage is:
instance HasPostgres (HandlerT App IO) where withPGConnection = withPGPool appPGPool
withPGPoolPrim :: MonadBaseControl IO m => m PGPool -> (Connection -> m a) -> m a Source
Another combinator to implement withPGConnection
instance HasPostgres (OurMonadT IO) where withPGConnection = withPGPoolPrim $ getPGPool <$> getSomeThing