hasql-transaction-0.5: A composable abstraction over the retryable transactions for Hasql

Safe Haskell | None
Language | Haskell2010

Hasql.Transaction

Contents

- Transaction settings
- Transaction monad

Description

An API for declaration of transactions.

Synopsis

- data Mode
  - = Read
  - | Write
- data IsolationLevel
  - = ReadCommitted
  - | RepeatableRead
  - | Serializable
- data Transaction a
- condemn :: Transaction ()
- sql :: ByteString -> Transaction ()
- query :: a -> Query a b -> Transaction b

# Transaction settings

data Mode #

Constructors

Read | Read-only. No writes possible.
Write | Write and commit.

Instances

Bounded Mode # |
Methods minBound :: Mode # maxBound :: Mode #
Enum Mode # |
Methods succ :: Mode -> Mode # pred :: Mode -> Mode # toEnum :: Int -> Mode # fromEnum :: Mode -> Int # enumFrom :: Mode -> [Mode] # enumFromThen :: Mode -> Mode -> [Mode] # enumFromTo :: Mode -> Mode -> [Mode] # enumFromThenTo :: Mode -> Mode -> Mode -> [Mode] #
Eq Mode # |
Methods (==) :: Mode -> Mode -> Bool # (/=) :: Mode -> Mode -> Bool #
Ord Mode # |
Methods compare :: Mode -> Mode -> Ordering # (<) :: Mode -> Mode -> Bool # (<=) :: Mode -> Mode -> Bool # (>) :: Mode -> Mode -> Bool # (>=) :: Mode -> Mode -> Bool # max :: Mode -> Mode -> Mode # min :: Mode -> Mode -> Mode #
Show Mode # |
Methods showsPrec :: Int -> Mode -> ShowS # show :: Mode -> String # showList :: [Mode] -> ShowS #

data IsolationLevel #

For reference see the Postgres' documentation.

Constructors

ReadCommitted |
RepeatableRead |
Serializable |

Instances

Bounded IsolationLevel # |
Methods minBound :: IsolationLevel # maxBound :: IsolationLevel #
Enum IsolationLevel # |
Methods succ :: IsolationLevel -> IsolationLevel # pred :: IsolationLevel -> IsolationLevel # toEnum :: Int -> IsolationLevel # fromEnum :: IsolationLevel -> Int # enumFrom :: IsolationLevel -> [IsolationLevel] # enumFromThen :: IsolationLevel -> IsolationLevel -> [IsolationLevel] # enumFromTo :: IsolationLevel -> IsolationLevel -> [IsolationLevel] # enumFromThenTo :: IsolationLevel -> IsolationLevel -> IsolationLevel -> [IsolationLevel] #
Eq IsolationLevel # |
Methods (==) :: IsolationLevel -> IsolationLevel -> Bool # (/=) :: IsolationLevel -> IsolationLevel -> Bool #
Ord IsolationLevel # |
Methods compare :: IsolationLevel -> IsolationLevel -> Ordering # (<) :: IsolationLevel -> IsolationLevel -> Bool # (<=) :: IsolationLevel -> IsolationLevel -> Bool # (>) :: IsolationLevel -> IsolationLevel -> Bool # (>=) :: IsolationLevel -> IsolationLevel -> Bool # max :: IsolationLevel -> IsolationLevel -> IsolationLevel # min :: IsolationLevel -> IsolationLevel -> IsolationLevel #
Show IsolationLevel # |
Methods showsPrec :: Int -> IsolationLevel -> ShowS # show :: IsolationLevel -> String # showList :: [IsolationLevel] -> ShowS #

# Transaction monad

data Transaction a #

A composable abstraction over the retryable transactions.

Executes multiple queries under the specified mode and isolation level, while automatically retrying the transaction in case of conflicts. Thus this abstraction closely reproduces the behaviour of `STM`.

Instances

Monad Transaction # |
Methods (>>=) :: Transaction a -> (a -> Transaction b) -> Transaction b # (>>) :: Transaction a -> Transaction b -> Transaction b # return :: a -> Transaction a # fail :: String -> Transaction a #
Functor Transaction # |
Methods fmap :: (a -> b) -> Transaction a -> Transaction b # (<$) :: a -> Transaction b -> Transaction a #
Applicative Transaction # |
Methods pure :: a -> Transaction a # (<*>) :: Transaction (a -> b) -> Transaction a -> Transaction b # (*>) :: Transaction a -> Transaction b -> Transaction b # (<*) :: Transaction a -> Transaction b -> Transaction a #

condemn :: Transaction () #

Cause transaction to eventually roll back.

sql :: ByteString -> Transaction () #

Possibly a multi-statement query, which however cannot be parameterized or prepared, nor can any results of it be collected.

query :: a -> Query a b -> Transaction b #

Parameters and a specification of the parametric query to apply them to.