-- | Definition of internal DBT state.
module Database.PostgreSQL.PQTypes.Internal.State (
    DBState(..)
  ) where

import Database.PostgreSQL.PQTypes.FromRow
import Database.PostgreSQL.PQTypes.Internal.Connection
import Database.PostgreSQL.PQTypes.Internal.QueryResult
import Database.PostgreSQL.PQTypes.SQL.Class
import Database.PostgreSQL.PQTypes.Transaction.Settings

-- | Internal DB state.
data DBState m = DBState
  { -- | Active connection.
    forall (m :: * -> *). DBState m -> Connection
dbConnection          :: !Connection
    -- | Supplied connection source.
  , forall (m :: * -> *). DBState m -> ConnectionSourceM m
dbConnectionSource    :: !(ConnectionSourceM m)
    -- | Current transaction settings.
  , forall (m :: * -> *). DBState m -> TransactionSettings
dbTransactionSettings :: !TransactionSettings
    -- | Last SQL query that was executed.
  , forall (m :: * -> *). DBState m -> SomeSQL
dbLastQuery           :: !SomeSQL
    -- | Whether running query should override 'dbLastQuery'.
  , forall (m :: * -> *). DBState m -> Bool
dbRecordLastQuery     :: !Bool
    -- | Current query result.
  , forall (m :: * -> *).
DBState m -> forall row. FromRow row => Maybe (QueryResult row)
dbQueryResult         :: !(forall row. FromRow row => Maybe (QueryResult row))
  }