module Database.PostgreSQL.PQTypes.Internal.State
( DBState(..)
, updateStateWith
) where
import Foreign.ForeignPtr
import Database.PostgreSQL.PQTypes.FromRow
import Database.PostgreSQL.PQTypes.Internal.C.Types
import Database.PostgreSQL.PQTypes.Internal.Connection
import Database.PostgreSQL.PQTypes.Internal.QueryResult
import Database.PostgreSQL.PQTypes.SQL.Class
import Database.PostgreSQL.PQTypes.Transaction.Settings
data DBState m = DBState
{
forall (m :: * -> *). DBState m -> Connection
dbConnection :: !Connection
, forall (m :: * -> *). DBState m -> ConnectionSourceM m
dbConnectionSource :: !(ConnectionSourceM m)
, forall (m :: * -> *). DBState m -> TransactionSettings
dbTransactionSettings :: !TransactionSettings
, forall (m :: * -> *). DBState m -> SomeSQL
dbLastQuery :: !SomeSQL
, forall (m :: * -> *). DBState m -> Bool
dbRecordLastQuery :: !Bool
, forall (m :: * -> *).
DBState m -> forall row. FromRow row => Maybe (QueryResult row)
dbQueryResult :: !(forall row. FromRow row => Maybe (QueryResult row))
}
updateStateWith :: IsSQL sql => DBState m -> sql -> ForeignPtr PGresult -> DBState m
updateStateWith :: forall sql (m :: * -> *).
IsSQL sql =>
DBState m -> sql -> ForeignPtr PGresult -> DBState m
updateStateWith DBState m
st sql
sql ForeignPtr PGresult
res = DBState m
st
{ dbLastQuery :: SomeSQL
dbLastQuery = if forall (m :: * -> *). DBState m -> Bool
dbRecordLastQuery DBState m
st then forall sql. IsSQL sql => sql -> SomeSQL
SomeSQL sql
sql else forall (m :: * -> *). DBState m -> SomeSQL
dbLastQuery DBState m
st
, dbQueryResult :: forall row. FromRow row => Maybe (QueryResult row)
dbQueryResult = forall a. a -> Maybe a
Just QueryResult
{ qrSQL :: SomeSQL
qrSQL = forall sql. IsSQL sql => sql -> SomeSQL
SomeSQL sql
sql
, qrResult :: ForeignPtr PGresult
qrResult = ForeignPtr PGresult
res
, qrFromRow :: row -> row
qrFromRow = forall a. a -> a
id
}
}