https://github.com/lightools/transaction-nesting
Nesting database transactions with dibi connection.
https://github.com/lightools/transaction-nesting
database-transactions dibi
Last synced: 2 months ago
JSON representation
Nesting database transactions with dibi connection.
- Host: GitHub
- URL: https://github.com/lightools/transaction-nesting
- Owner: lightools
- License: other
- Created: 2016-03-22T13:09:46.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-12T14:33:30.000Z (about 10 years ago)
- Last Synced: 2025-12-14T21:38:56.292Z (6 months ago)
- Topics: database-transactions, dibi
- Language: PHP
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Introduction
This library allows you to nest database transactions over dibi connection.
## Installation
```sh
$ composer require lightools/transaction-nesting
```
## Simple usage
TransactionManager will begin/commit/rollback database transaction only if there is no other transaction running.
So if you try to start new transaction when some transaction is active, it will not fail with error ```There is already an active transaction```.
This means you can nest transactions safely and TransactionManager will make sure that only the outer transaction will be performed.
```php
$dibi = new Dibi\Connection($config);
$manager = new Lightools\TransactionNesting\TransactionManager($dibi);
$manager->transactional(function () {
// your logic
});
```
Of course, this will break if you perform some query causing implicit commit (for example ALTER TABLE on MySQL).
## How to run tests
```sh
$ vendor/bin/tester -c tests/php.ini -d extension_dir=ext tests
```