packages feed

hasql-2.2.0.0 / src / connection-state / Hasql / ConnectionState.hs

-- |-- This module defines the internal state of a database connection.module Hasql.ConnectionState  ( ConnectionState (..),    toStatementCache,    fromConnection,    setPreparedStatements,    setStatementCache,    setConnection,    setOidCache,    mapStatementCache,    mapOidCache,    traverseStatementCache,  )whereimport Hasql.ConnectionState.OidCache qualified as OidCacheimport Hasql.ConnectionState.StatementCache qualified as StatementCacheimport Hasql.Platform.Preludeimport Pqi qualified as Pq-- |-- The internal state of a database connection.data ConnectionState = ConnectionState  { -- | Whether prepared statements are enabled.    preparedStatements :: Bool,    -- | The statement cache for prepared statements.    statementCache :: StatementCache.StatementCache,    -- | The OID cache for type name to OID mapping.    oidCache :: OidCache.OidCache,    -- | The underlying database connection.    connection :: Pq.Connection  }toStatementCache :: ConnectionState -> StatementCache.StatementCachetoStatementCache ConnectionState {..} = statementCachefromConnection :: Pq.Connection -> ConnectionStatefromConnection connection =  ConnectionState    { preparedStatements = False,      statementCache = StatementCache.empty,      oidCache = OidCache.empty,      connection = connection    }setPreparedStatements :: Bool -> ConnectionState -> ConnectionStatesetPreparedStatements preparedStatements connectionState =  connectionState {preparedStatements = preparedStatements}setStatementCache :: StatementCache.StatementCache -> ConnectionState -> ConnectionStatesetStatementCache statementCache connectionState =  connectionState {statementCache = statementCache}setConnection :: Pq.Connection -> ConnectionState -> ConnectionStatesetConnection connection connectionState =  connectionState {connection = connection}setOidCache :: OidCache.OidCache -> ConnectionState -> ConnectionStatesetOidCache oidCache connectionState =  connectionState {oidCache}mapStatementCache ::  (StatementCache.StatementCache -> StatementCache.StatementCache) ->  (ConnectionState -> ConnectionState)mapStatementCache f ConnectionState {..} =  ConnectionState    { statementCache = f statementCache,      ..    }mapOidCache ::  (OidCache.OidCache -> OidCache.OidCache) ->  (ConnectionState -> ConnectionState)mapOidCache f ConnectionState {..} =  ConnectionState    { oidCache = f oidCache,      ..    }traverseStatementCache ::  (Functor f) =>  (StatementCache.StatementCache -> f StatementCache.StatementCache) ->  (ConnectionState -> f ConnectionState)traverseStatementCache f ConnectionState {..} =  fmap    ( \newStatementCache ->        ConnectionState          { statementCache = newStatementCache,            ..          }    )    (f statementCache)