graphql-engine-1.0.0: GraphQL API over Postgres
Safe HaskellNone
LanguageHaskell2010

Database.MSSQL.Transaction

Synopsis

Documentation

newtype TxET e m a Source #

The transaction command to run, parameterised over: e - the exception type (usually MSSQLTxError) m - some Monad, (usually some MonadIO) a - the successful result type

Constructors

TxET 

Fields

Instances

Instances details
Monad m => MonadReader Connection (TxET e m) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

ask :: TxET e m Connection #

local :: (Connection -> Connection) -> TxET e m a -> TxET e m a #

reader :: (Connection -> a) -> TxET e m a #

Monad m => MonadError e (TxET e m) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

throwError :: e -> TxET e m a #

catchError :: TxET e m a -> (e -> TxET e m a) -> TxET e m a #

MonadTrans (TxET e) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

lift :: Monad m => m a -> TxET e m a #

MFunctor (TxET e :: (Type -> Type) -> Type -> Type) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

hoist :: forall m n (b :: k). Monad m => (forall a. m a -> n a) -> TxET e m b -> TxET e n b

Monad m => Monad (TxET e m) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

(>>=) :: TxET e m a -> (a -> TxET e m b) -> TxET e m b #

(>>) :: TxET e m a -> TxET e m b -> TxET e m b #

return :: a -> TxET e m a #

Functor m => Functor (TxET e m) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

fmap :: (a -> b) -> TxET e m a -> TxET e m b #

(<$) :: a -> TxET e m b -> TxET e m a #

MonadFix m => MonadFix (TxET e m) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

mfix :: (a -> TxET e m a) -> TxET e m a #

Monad m => Applicative (TxET e m) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

pure :: a -> TxET e m a #

(<*>) :: TxET e m (a -> b) -> TxET e m a -> TxET e m b #

liftA2 :: (a -> b -> c) -> TxET e m a -> TxET e m b -> TxET e m c #

(*>) :: TxET e m a -> TxET e m b -> TxET e m b #

(<*) :: TxET e m a -> TxET e m b -> TxET e m a #

MonadIO m => MonadIO (TxET e m) Source # 
Instance details

Defined in Database.MSSQL.Transaction

Methods

liftIO :: IO a -> TxET e m a #

MonadIO m => MonadMSSQLTx (TxET QErr m) Source # 
Instance details

Defined in Hasura.Backends.MSSQL.Connection

Methods

liftMSSQLTx :: TxE QErr a -> TxET QErr m a Source #

CacheRM m => CacheRM (TxET e m) Source # 
Instance details

Defined in Hasura.RQL.Types.SchemaCache

data MSSQLTxError Source #

Error type generally used in TxET.

Constructors

MSSQLQueryError !Query !ODBCException 
MSSQLConnError !ODBCException 
MSSQLInternal !Text 

Instances

Instances details
Eq MSSQLTxError Source # 
Instance details

Defined in Database.MSSQL.Transaction

Show MSSQLTxError Source # 
Instance details

Defined in Database.MSSQL.Transaction

type TxE e a = TxET e IO a Source #

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.

buildGenericQueryTxE Source #

Arguments

:: MonadIO m 
=> (MSSQLTxError -> e)

map MSSQLTxError to some other type

-> query

query to run

-> (query -> Query)

how to map a query to a Query

-> (Connection -> query -> IO a)

run the query on a provided Connection

-> 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

Constructors

MSSQLResult [[Value]] 

rawQueryE Source #

Arguments

:: 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

Constructors

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.

beginTx :: MonadIO m => TxT m () Source #

commitTx :: MonadIO m => TxT m () Source #