Safe Haskell | None |
---|---|
Language | Haskell2010 |
DSL for composition of transactions with automated conflict resolution.
Synopsis
- transact :: Transaction a -> Session a
- data Transaction a
- statement :: Mode -> Level -> Statement i o -> i -> Transaction o
- sql :: Mode -> Level -> ByteString -> Transaction ()
- session :: Mode -> Level -> Session a -> Transaction a
- condemn :: Transaction ()
- restrict :: Level -> Transaction a -> Transaction a
- data Mode
- data Level
Sessions
transact :: Transaction a -> Session a Source #
Execute transaction in session.
Transaction
data Transaction a Source #
Composable transaction providing for automated conflict resolution.
Mode and level is associated with the transaction, which makes them participate in composition. In a composed transaction they become the strictest of the ones associated with the transactions that constitute it. This allows you to safely compose transactions with different ACID guarantees.
It cannot have an instance of Monad,
because it makes it impossible to implement composition of
mode and level associated with consituent transactions.
It still however is possible to compose transactions
in such a way that the result of a transaction is used
to decide which transaction to execute next,
thanks to the recently discovered Selective
interface.
Supports alternative branching, where the alternative gets executed in case of a transaction conflict.
Instances
Functor Transaction Source # | |
Defined in Hasql.Transaction fmap :: (a -> b) -> Transaction a -> Transaction b # (<$) :: a -> Transaction b -> Transaction a # | |
Applicative Transaction Source # | |
Defined in Hasql.Transaction pure :: a -> Transaction a # (<*>) :: Transaction (a -> b) -> Transaction a -> Transaction b # liftA2 :: (a -> b -> c) -> Transaction a -> Transaction b -> Transaction c # (*>) :: Transaction a -> Transaction b -> Transaction b # (<*) :: Transaction a -> Transaction b -> Transaction a # | |
Alternative Transaction Source # | |
Defined in Hasql.Transaction empty :: Transaction a # (<|>) :: Transaction a -> Transaction a -> Transaction a # some :: Transaction a -> Transaction [a] # many :: Transaction a -> Transaction [a] # | |
Selective Transaction Source # | |
Defined in Hasql.Transaction select :: Transaction (Either a b) -> Transaction (a -> b) -> Transaction b # |
statement :: Mode -> Level -> Statement i o -> i -> Transaction o Source #
Execute a single statement under mode and level.
Warning: The statement must not be transaction-related
like BEGIN
, COMMIT
or ABORT
, otherwise you'll break the abstraction.
sql :: Mode -> Level -> ByteString -> Transaction () Source #
Execute a possibly multistatement SQL string under a mode and level. SQL strings cannot be dynamically parameterized or produce a result.
Warning: SQL must not be transaction-related
like BEGIN
, COMMIT
or ABORT
, otherwise you'll break the abstraction.
session :: Mode -> Level -> Session a -> Transaction a Source #
Execute a composition of statements under the same mode and level.
Warning:
- You must know that it is possible to break the abstraction,
if you execute statements such as
BEGIN
inside of the session. - For the same reason you cannot execute other transactions inside of that session.
- You must beware that in case of conflicts any IO code that you may lift into session will get executed multiple times. This is the way the automatic conflict resolution works: the transaction gets retried, when a conflict arises. So be cautious about doing any mutations or rocket launches in that IO! Simply pinging for things such as current time is totally fine though. Still it's not recommended because it's often a symptom of bad application design.
Due to the mentioned it's highly advised to keep all the session code inside of the definition of a transaction. Thus you'll be guaranteed to have control over what's going on inside of the executed session and it will not be possible for this code to be affected by any outside changes or used elsewhere.
condemn :: Transaction () Source #
Cause transaction to eventually roll back.
This allows to perform some transactional actions, collecting their results, and decide, whether to commit the introduced changes to the DB based on those results, as well as emit those results outside of the transaction.
restrict :: Level -> Transaction a -> Transaction a Source #
Restrict the transaction isolation level.
Will pick up the strictest level among the one you've specified and the one associated with the updated transaction.
Settings
Execution mode: either read or write.
Transaction isolation level.
For reference see the Postgres' documentation.