unison-sqlite-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Sqlite.Transaction

Synopsis

Transaction management

data Transaction a Source #

Instances

Instances details
Applicative Transaction Source # 
Instance details

Defined in Unison.Sqlite.Transaction

Methods

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 #

Functor Transaction Source # 
Instance details

Defined in Unison.Sqlite.Transaction

Methods

fmap :: (a -> b) -> Transaction a -> Transaction b #

(<$) :: a -> Transaction b -> Transaction a #

Monad Transaction Source # 
Instance details

Defined in Unison.Sqlite.Transaction

Methods

(>>=) :: Transaction a -> (a -> Transaction b) -> Transaction b #

(>>) :: Transaction a -> Transaction b -> Transaction b #

return :: a -> Transaction a #

Monoid a => Monoid (Transaction a) Source # 
Instance details

Defined in Unison.Sqlite.Transaction

Semigroup a => Semigroup (Transaction a) Source # 
Instance details

Defined in Unison.Sqlite.Transaction

runTransaction :: (MonadIO m, HasCallStack) => Connection -> Transaction a -> m a Source #

Run a transaction on the given connection.

runTransactionWithRollback :: (MonadIO m, HasCallStack) => Connection -> ((forall void. a -> Transaction void) -> Transaction a) -> m a Source #

Run a transaction on the given connection, providing a function that can short-circuit (and roll back) the transaction.

runReadOnlyTransaction :: (MonadUnliftIO m, HasCallStack) => Connection -> ((forall x. Transaction x -> m x) -> m a) -> m a Source #

Run a transaction that is known to only perform reads.

The action is provided a function that peels off the Transaction newtype without sending the corresponding BEGIN/COMMIT statements.

The transaction is never retried, so it is (more) safe to interleave arbitrary IO actions. If the transaction does attempt a write and gets SQLITE_BUSY, it's your fault!

runWriteTransaction :: (HasCallStack, MonadUnliftIO m) => Connection -> ((forall x. Transaction x -> m x) -> m a) -> m a Source #

Run a transaction that is known to perform at least one write.

The action is provided a function that peels off the Transaction newtype without sending the corresponding BEGIN/COMMIT statements.

The transaction is never retried, so it is (more) safe to interleave arbitrary IO actions.

cacheTransaction :: forall k v. Cache k v -> (k -> Transaction v) -> k -> Transaction v Source #

Wrap a transaction with a cache; cache hits will not hit SQLite.

savepoint :: Transaction (Either a a) -> Transaction a Source #

Perform an atomic sub-computation within a transaction; if it returns Left, it's rolled back.

Unsafe things

unsafeIO :: HasCallStack => IO a -> Transaction a Source #

Perform IO inside a transaction, which should be idempotent, because it may be run more than once if the transaction needs to retry.

Warning: attempting to run a transaction inside a transaction will cause an exception!

unsafeUnTransaction :: Transaction a -> Connection -> IO a Source #

Unwrap the transaction newtype, throwing away the sending of BEGIN/COMMIT + automatic retry.

Executing queries

Without results

With results

With checks

Rows modified