| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasql.Pool.Config
Description
DSL for construction of configs.
Synopsis
- data Config
- settings :: [Setting] -> Config
- data Setting
- size :: Int -> Setting
- acquisitionTimeout :: DiffTime -> Setting
- agingTimeout :: DiffTime -> Setting
- idlenessTimeout :: DiffTime -> Setting
- staticConnectionSettings :: Settings -> Setting
- dynamicConnectionSettings :: IO Settings -> Setting
- observationHandler :: (Observation -> IO ()) -> Setting
- initSession :: Session () -> Setting
- reuseOrder :: ReuseOrder -> Setting
- data ReuseOrder
Documentation
settings :: [Setting] -> Config #
Compile config from a list of settings. Latter settings override the preceding in cases of conflicts.
acquisitionTimeout :: DiffTime -> Setting #
Connection acquisition timeout.
10 seconds by default.
agingTimeout :: DiffTime -> Setting #
Maximal connection lifetime.
Determines how long is available for reuse. After the timeout passes and an active session is finished the connection will be closed releasing a slot in the pool for a fresh connection to be established.
This is useful as a healthy measure for resetting the server-side caches.
1 day by default.
idlenessTimeout :: DiffTime -> Setting #
Maximal connection idle time.
How long to keep a connection open when it's not being used.
10 minutes by default.
staticConnectionSettings :: Settings -> Setting #
Connection string.
By default it is:
"postgresql://postgres:postgres@localhost:5432/postgres"
dynamicConnectionSettings :: IO Settings -> Setting #
Action providing connection settings.
Gets used each time a connection gets established by the pool. This may be useful for some authorization models.
By default it is:
pure "postgresql://postgres:postgres@localhost:5432/postgres"
observationHandler :: (Observation -> IO ()) -> Setting #
Observation handler.
Typically it's used for monitoring the state of the pool via metrics and logging.
An observation handler must not throw. Synchronous exceptions from it are discarded; asynchronous exceptions are honored. Its failure never affects the session result or the pool's state.
If the provided action is not lightweight, it's recommended to use intermediate bufferring via channels like TBQueue to avoid occupying the pool management thread for too long.
E.g., if the action is , then reading from it and processing can be done on a separate thread.atomically . writeTBQueue yourQueue
By default it is:
const (pure ())
initSession :: Session () -> Setting #
Initial session.
Gets executed on every connection upon acquisition. Lets you specify the connection-wide settings.
E.g., you can set the search path for all the sessions executed by the pool by executing the following:
initSession (Session.sql "SET search_path TO schema1, schema2, public;")
reuseOrder :: ReuseOrder -> Setting #
Which of the idle connections a pool request gets.
With LIFO, the pool shrinks to the connections the load needs: the rest
time out as idle (see idlenessTimeout). With FIFO, steady load keeps
every connection open.
FIFO by default.
data ReuseOrder #
Which of the idle connections a pool request gets.
Constructors
| LIFO | Last in, first out: the one returned most recently. The pool keeps reusing the few connections the load needs, so the rest time out as idle, and the ones in use keep their caches warm. |
| FIFO | First in, first out: the one returned longest ago. Pool requests cycle through all the connections, so steady load keeps every connection open. |
Instances
| Eq ReuseOrder # | |
Defined in Hasql.Pool.Config.ReuseOrder | |
| Show ReuseOrder # | |
Defined in Hasql.Pool.Config.ReuseOrder Methods showsPrec :: Int -> ReuseOrder -> ShowS # show :: ReuseOrder -> String # showList :: [ReuseOrder] -> ShowS # | |