| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Hasql.Pool
Pool
acquire :: Adapter -> Config -> IO Pool #
Create a connection-pool.
No connections actually get established by this function. It is delegated
to use.
If you want to ensure that the pool connects fine at the initialization phase, just run use with an empty session (pure ()) and check for errors.
The Adapter determines which connection implementation the pool uses, e.g. an FFI adapter backed by postgresql-libpq, or a pure Haskell one. Pick one from an adapter package such as pqi-ffi or pqi-native.
use :: Pool -> Session a -> IO (Either UsageError a) #
Use a connection from the pool to run a session and return the connection to the pool, when finished.
Session failing with a ConnectionSessionError or leaving the
connection in the ConnectionBad state gets interpreted as a loss of
connection. In such case the connection does not get returned to the pool
and a slot gets freed up for a new connection to be established the next
time one is needed. The error still gets returned from this function.
Warning: Due to the mechanism mentioned above you should avoid intercepting this error type from within sessions.
When no connection is available, the pool requests wait for one in the order they came, and a later pool request doesn't take a connection while others wait.
Release all the idle connections in the pool, and mark the in-use connections to be released after use. Any connections acquired after the call will be freshly established.
The pool remains usable after this action. So you can use this function to reset the connections in the pool. Naturally, you can also use it to release the resources.
Errors
data UsageError #
Union over all errors that use can result in.
Constructors
| ConnectionUsageError ConnectionError | Attempt to establish a connection failed. |
| SessionUsageError SessionError | Session execution failed. |
| AcquisitionTimeoutUsageError | Timeout acquiring a connection. |
Instances
| Eq UsageError # | |
Defined in Hasql.Pool | |
| Exception UsageError # | |
Defined in Hasql.Pool Methods toException :: UsageError -> SomeException # fromException :: SomeException -> Maybe UsageError # displayException :: UsageError -> String # backtraceDesired :: UsageError -> Bool # | |
| Show UsageError # | |
Defined in Hasql.Pool Methods showsPrec :: Int -> UsageError -> ShowS # show :: UsageError -> String # showList :: [UsageError] -> ShowS # | |