postgresql-config-0.1.0: Types for easy adding postgresql configuration to your program

Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Config

Contents

Synopsis

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

Constructors

PostgresConf 

Fields

pgConnStr :: ByteString

The connection string.

pgPoolSize :: Int

How many connections should be held on the connection pool.

pgPoolTimeout :: NominalDiffTime

Timeout to stay connection active

pgPoolStripes :: Int

Stripes in the pool

newtype PGPool Source

Connection pool. Must be created from settings using createPGPool

Constructors

PGPool 

Pool creation

createPGPool :: PostgresConf -> IO PGPool Source

Create pool from parsed configuration

createPGPoolWithCallback Source

Arguments

:: 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