Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Transaction a
- runTransaction :: (MonadIO m, HasCallStack) => Connection -> Transaction a -> m a
- runTransactionWithRollback :: (MonadIO m, HasCallStack) => Connection -> ((forall void. a -> Transaction void) -> Transaction a) -> m a
- runReadOnlyTransaction :: (MonadUnliftIO m, HasCallStack) => Connection -> ((forall x. Transaction x -> m x) -> m a) -> m a
- runWriteTransaction :: (HasCallStack, MonadUnliftIO m) => Connection -> ((forall x. Transaction x -> m x) -> m a) -> m a
- cacheTransaction :: forall k v. Cache k v -> (k -> Transaction v) -> k -> Transaction v
- savepoint :: Transaction (Either a a) -> Transaction a
- unsafeIO :: HasCallStack => IO a -> Transaction a
- unsafeGetConnection :: Transaction Connection
- unsafeUnTransaction :: Transaction a -> Connection -> IO a
- execute :: HasCallStack => Sql -> Transaction ()
- executeStatements :: HasCallStack => Text -> Transaction ()
- queryStreamRow :: (FromRow a, HasCallStack) => Sql -> (Transaction (Maybe a) -> Transaction r) -> Transaction r
- queryStreamCol :: forall a r. (FromField a, HasCallStack) => Sql -> (Transaction (Maybe a) -> Transaction r) -> Transaction r
- queryListRow :: (FromRow a, HasCallStack) => Sql -> Transaction [a]
- queryListCol :: (FromField a, HasCallStack) => Sql -> Transaction [a]
- queryMaybeRow :: (FromRow a, HasCallStack) => Sql -> Transaction (Maybe a)
- queryMaybeCol :: (FromField a, HasCallStack) => Sql -> Transaction (Maybe a)
- queryOneRow :: (FromRow a, HasCallStack) => Sql -> Transaction a
- queryOneCol :: (FromField a, HasCallStack) => Sql -> Transaction a
- queryListRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Sql -> ([a] -> Either e r) -> Transaction r
- queryListColCheck :: (FromField a, SqliteExceptionReason e, HasCallStack) => Sql -> ([a] -> Either e r) -> Transaction r
- queryMaybeRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Sql -> (a -> Either e r) -> Transaction (Maybe r)
- queryMaybeColCheck :: (FromField a, SqliteExceptionReason e, HasCallStack) => Sql -> (a -> Either e r) -> Transaction (Maybe r)
- queryOneRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Sql -> (a -> Either e r) -> Transaction r
- queryOneColCheck :: (FromField a, SqliteExceptionReason e, HasCallStack) => Sql -> (a -> Either e r) -> Transaction r
- rowsModified :: Transaction Int
Transaction management
data Transaction a Source #
Instances
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
execute :: HasCallStack => Sql -> Transaction () Source #
executeStatements :: HasCallStack => Text -> Transaction () Source #
With results
queryStreamRow :: (FromRow a, HasCallStack) => Sql -> (Transaction (Maybe a) -> Transaction r) -> Transaction r Source #
queryStreamCol :: forall a r. (FromField a, HasCallStack) => Sql -> (Transaction (Maybe a) -> Transaction r) -> Transaction r Source #
queryListRow :: (FromRow a, HasCallStack) => Sql -> Transaction [a] Source #
queryListCol :: (FromField a, HasCallStack) => Sql -> Transaction [a] Source #
queryMaybeRow :: (FromRow a, HasCallStack) => Sql -> Transaction (Maybe a) Source #
queryMaybeCol :: (FromField a, HasCallStack) => Sql -> Transaction (Maybe a) Source #
queryOneRow :: (FromRow a, HasCallStack) => Sql -> Transaction a Source #
queryOneCol :: (FromField a, HasCallStack) => Sql -> Transaction a Source #
With checks
queryListRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Sql -> ([a] -> Either e r) -> Transaction r Source #
queryListColCheck :: (FromField a, SqliteExceptionReason e, HasCallStack) => Sql -> ([a] -> Either e r) -> Transaction r Source #
queryMaybeRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Sql -> (a -> Either e r) -> Transaction (Maybe r) Source #
queryMaybeColCheck :: (FromField a, SqliteExceptionReason e, HasCallStack) => Sql -> (a -> Either e r) -> Transaction (Maybe r) Source #
queryOneRowCheck :: (FromRow a, SqliteExceptionReason e, HasCallStack) => Sql -> (a -> Either e r) -> Transaction r Source #
queryOneColCheck :: (FromField a, SqliteExceptionReason e, HasCallStack) => Sql -> (a -> Either e r) -> Transaction r Source #