Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype TxET e m a = TxET {}
- data MSSQLTxError
- = MSSQLQueryError !Query !ODBCException
- | MSSQLConnError !ODBCException
- | MSSQLInternal !Text
- type TxE e a = TxET e IO a
- type TxT m a = TxET MSSQLTxError m a
- runTx :: (MonadIO m, MonadBaseControl IO m) => TxT m a -> MSSQLPool -> ExceptT MSSQLTxError m a
- runTxE :: (MonadIO m, MonadBaseControl IO m) => (MSSQLTxError -> e) -> TxET e m a -> MSSQLPool -> ExceptT e m a
- unitQuery :: MonadIO m => Query -> TxT m ()
- unitQueryE :: MonadIO m => (MSSQLTxError -> e) -> Query -> TxET e m ()
- singleRowQuery :: forall a m. (MonadIO m, FromRow a) => Query -> TxT m a
- singleRowQueryE :: forall m a e. (MonadIO m, FromRow a) => (MSSQLTxError -> e) -> Query -> TxET e m a
- forJsonQueryE :: forall m e. MonadIO m => (MSSQLTxError -> e) -> Query -> TxET e m Text
- multiRowQuery :: forall a m. (MonadIO m, FromRow a) => Query -> TxT m [a]
- multiRowQueryE :: forall m a e. (MonadIO m, FromRow a) => (MSSQLTxError -> e) -> Query -> TxET e m [a]
- buildGenericQueryTxE :: MonadIO m => (MSSQLTxError -> e) -> query -> (query -> Query) -> (Connection -> query -> IO a) -> TxET e m a
- withTxET :: Monad m => (e1 -> e2) -> TxET e1 m a -> TxET e2 m a
- newtype MSSQLResult = MSSQLResult [[Value]]
- rawQueryE :: MonadIO m => (MSSQLTxError -> e) -> (MSSQLResult -> Either String a) -> Query -> TxET e m a
- execQuery :: forall m a query. MonadIO m => query -> (query -> Query) -> (query -> IO a) -> ExceptT MSSQLTxError m a
- execTx :: Connection -> TxET e m a -> ExceptT e m a
- data TransactionState
- asTransaction :: forall e a m. MonadIO m => (MSSQLTxError -> e) -> (Connection -> ExceptT e m a) -> Connection -> ExceptT e m a
- beginTx :: MonadIO m => TxT m ()
- commitTx :: MonadIO m => TxT m ()
- rollbackTx :: MonadIO m => TxT m ()
- getTransactionState :: MonadIO m => TxT m TransactionState
Documentation
The transaction command to run, parameterised over:
e - the exception type (usually MSSQLTxError
)
m - some Monad, (usually some MonadIO
)
a - the successful result type
Instances
Monad m => MonadReader Connection (TxET e m) Source # | |
Monad m => MonadError e (TxET e m) Source # | |
Defined in Database.MSSQL.Transaction throwError :: e -> TxET e m a # catchError :: TxET e m a -> (e -> TxET e m a) -> TxET e m a # | |
MonadTrans (TxET e) Source # | |
Defined in Database.MSSQL.Transaction | |
MFunctor (TxET e :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Database.MSSQL.Transaction | |
Monad m => Monad (TxET e m) Source # | |
Functor m => Functor (TxET e m) Source # | |
MonadFix m => MonadFix (TxET e m) Source # | |
Defined in Database.MSSQL.Transaction | |
Monad m => Applicative (TxET e m) Source # | |
MonadIO m => MonadIO (TxET e m) Source # | |
Defined in Database.MSSQL.Transaction | |
MonadIO m => MonadMSSQLTx (TxET QErr m) Source # | |
Defined in Hasura.Backends.MSSQL.Connection | |
CacheRM m => CacheRM (TxET e m) Source # | |
Defined in Hasura.RQL.Types.SchemaCache askSchemaCache :: TxET e m SchemaCache Source # |
data MSSQLTxError Source #
Error type generally used in TxET
.
MSSQLQueryError !Query !ODBCException | |
MSSQLConnError !ODBCException | |
MSSQLInternal !Text |
Instances
Eq MSSQLTxError Source # | |
Defined in Database.MSSQL.Transaction (==) :: MSSQLTxError -> MSSQLTxError -> Bool # (/=) :: MSSQLTxError -> MSSQLTxError -> Bool # | |
Show MSSQLTxError Source # | |
Defined in Database.MSSQL.Transaction showsPrec :: Int -> MSSQLTxError -> ShowS # show :: MSSQLTxError -> String # showList :: [MSSQLTxError] -> ShowS # |
type TxT m a = TxET MSSQLTxError m a Source #
The transaction command to run, returning an MSSQLTxError or the result.
runTx :: (MonadIO m, MonadBaseControl IO m) => TxT m a -> MSSQLPool -> ExceptT MSSQLTxError m a Source #
Run a command on the given connection wrapped in a transaction.
See runTxE
if you need to map the error type as well.
runTxE :: (MonadIO m, MonadBaseControl IO m) => (MSSQLTxError -> e) -> TxET e m a -> MSSQLPool -> ExceptT e m a Source #
Run a command on the given connection wrapped in a transaction.
unitQuery :: MonadIO m => Query -> TxT m () Source #
Useful for building transactions which return no data.
insertId :: TxT m () insertId = unitQuery "INSERT INTO some_table VALUES (1, "hello")"
See unitQueryE
if you need to map the error type as well.
unitQueryE :: MonadIO m => (MSSQLTxError -> e) -> Query -> TxET e m () Source #
Useful for building transactions which return no data.
singleRowQuery :: forall a m. (MonadIO m, FromRow a) => Query -> TxT m a Source #
Useful for building query transactions which return a single one row.
returnOne :: TxT m Int returnOne = singleRowQuery "SELECT 1"
See singleRowQueryE
if you need to map the error type as well.
singleRowQueryE :: forall m a e. (MonadIO m, FromRow a) => (MSSQLTxError -> e) -> Query -> TxET e m a Source #
Useful for building query transactions which return a single one row.
forJsonQueryE :: forall m e. MonadIO m => (MSSQLTxError -> e) -> Query -> TxET e m Text Source #
MSSQL splits up results that have a SELECT .. FOR JSON
at the top-level
into multiple rows with a single column, see
https://docs.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server?view=sql-server-ver15#output-of-the-for-json-clause
This function simply concatenates each single-column row into one long Text
string.
multiRowQuery :: forall a m. (MonadIO m, FromRow a) => Query -> TxT m [a] Source #
Useful for building query transactions which return multiple rows.
selectIds :: TxT m [Int] selectIds = multiRowQuery "SELECT id FROM author"
See multiRowQueryE
if you need to map the error type as well.
multiRowQueryE :: forall m a e. (MonadIO m, FromRow a) => (MSSQLTxError -> e) -> Query -> TxET e m [a] Source #
Useful for building query transactions which return multiple rows.
:: MonadIO m | |
=> (MSSQLTxError -> e) | map |
-> query | query to run |
-> (query -> Query) | how to map a query to a |
-> (Connection -> query -> IO a) | run the query on a provided |
-> TxET e m a |
Build a generic transaction out of an IO action.
withTxET :: Monad m => (e1 -> e2) -> TxET e1 m a -> TxET e2 m a Source #
Map the error type for a TxET
.
newtype MSSQLResult Source #
A successful result from a query is a list of rows where each row contains list of column values
MSSQLResult [[Value]] |
:: MonadIO m | |
=> (MSSQLTxError -> e) | Error modifier |
-> (MSSQLResult -> Either String a) | Result modifier with a failure |
-> Query | Query to run |
-> TxET e m a |
Packs a query, along with result and error converters into a TxET
.
Used by unitQueryE
, singleRowQueryE
, and multiRowQueryE
.
execQuery :: forall m a query. MonadIO m => query -> (query -> Query) -> (query -> IO a) -> ExceptT MSSQLTxError m a Source #
Combinator for abstracting over the query type and ensuring we catch exceptions.
Used by buildGenericQueryTxE
.
execTx :: Connection -> TxET e m a -> ExceptT e m a Source #
Run a TxET
with the given connection.
Used by runTxE
and asTransaction
.
data TransactionState Source #
The transaction state of the current connection
TSActive | Has an active transaction. |
TSNoActive | Has no active transaction. |
TSUncommittable | An error occurred that caused the transaction to be uncommittable. We cannot commit or rollback to a savepoint; we can only do a full rollback of the transaction. |
asTransaction :: forall e a m. MonadIO m => (MSSQLTxError -> e) -> (Connection -> ExceptT e m a) -> Connection -> ExceptT e m a Source #
Wraps an action in a transaction. Rolls back on errors.
rollbackTx :: MonadIO m => TxT m () Source #
getTransactionState :: MonadIO m => TxT m TransactionState Source #
Get the @TransactionState
of current connection
For more details, refer to https://docs.microsoft.com/en-us/sql/t-sql/functions/xact-state-transact-sql?view=sql-server-ver15