inlm/dibi-transactions

Nested transactions for Dibi.

Fund package maintenance!
Other

v1.0.0 2021-10-15 09:36 UTC

This package is auto-updated.

Last update: 2024-12-13 08:49:57 UTC


README

Build Status Downloads this Month Latest Stable Version License

Nested transactions for Dibi.

Donate

Installation

Download a latest package or use Composer:

composer require inlm/dibi-transactions

Inlm\Dibi-transactions requires PHP 5.6.0 or later and Dibi.

Usage

$connection = new Dibi\Connection();
$transactions = new Inlm\DibiTransactions\Transactions($connection);

transactional()

$value = $transactions->transactional(function () use ($connection) {
	$connection->query('...');
	$connection->query('...');
	return $value;
});

Transaction

$transaction = $transactions->createTransaction();

try {
	$connection->query('...');
	$connection->query('...');
	$transaction->commit();

} catch (Exception $e) {
	$transaction->rollback();
	throw $e;
}

Object Transaction throws error if you forget to call commit() or rollback(). It can be connected with Tracy:

$transactions->onUnresolved[] = array(Inlm\DibiTransactions\Bridges\Tracy::class, 'logUnresolved');

begin / commit / rollback

try {
	$transactions->begin();
	$connection->query('...');
	$connection->query('...');
	$transactions->commit();

} catch (Exception $e) {
	$transactions->rollback();
}

License: New BSD License
Author: Jan Pecha, https://www.janpecha.cz/