Skip to content

inlm/dibi-transactions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inlm\DibiTransactions

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/