2017 © Pedro Peláez
 

library ntdb

Nette Database Nested Transaction

image

minetro/ntdb

Nette Database Nested Transaction

  • Friday, December 9, 2016
  • by f3l1x
  • Repository
  • 2 Watchers
  • 4 Stars
  • 6,431 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 1 % Grown

The README.md

, (*1)

, (*2)

Website 🚀 contributte.org | Contact 👨🏻‍💻 f3l1x.io | Twitter 🐦 @contributte , (*3)

Disclaimer

:warning: This project is no longer being maintained. Please use contributte/database.
Composer minetro/ntdb
Version
PHP
License

Resources

Inspired by these articles:, (*4)

  • http://www.yiiframework.com/wiki/38/how-to-use-nested-db-transactions-mysql-5-postgresql/
  • http://www.kennynet.co.uk/2008/12/02/php-pdo-nested-transactions/
  • https://gist.github.com/neoascetic/5269127

Usage

Provide nested transaction via savepoints., (*5)

Support, (*6)

  • MySQL / MySQLi
  • PostgreSQL
  • SQLite

API, (*7)

  • $t->begin
  • $t->commit
  • $t->rollback
  • $t->transaction or $t->t
  • $t->promise

Begin

Starts transaction., (*8)

$t = new Transaction(new Connection(...));
$t->begin();

Commit

Commit changes in transaction., (*9)

$t = new Transaction(new Connection(...));
$t->begin();
// some changes..
$t->commit();

Rollback

Revert changes in transaction., (*10)

$t = new Transaction(new Connection(...));

$t->begin();
try {
    // some changes..
    $t->commit();
} catch (Exception $e) {
    $t->rollback();
}

Transaction

Combine begin, commit and rollback to one method., (*11)

On success it commits changes, if exceptions is thrown it rollbacks changes., (*12)

$t = new Transaction(new Connection(...));

$t->transaction(function() {
    // some changes..
});

// or alias

$t->t(function() {
    // some changes..
});

Promise

Another attitude to transaction., (*13)

$t = new Transaction(new Connection(...));

$t->promise()->then(
    function() {
        // Logic.. (save/update/remove some data)
    }, 
    function () {
        // Success.. (after commit)
    },
    function() {
        // Failed.. (after rollback)
    }
);

UnresolvedTransactionException

Log unresolved transaction., (*14)

Idea by Ondrej Mirtes (https://ondrej.mirtes.cz/detekce-neuzavrenych-transakci)., (*15)

$t = new Transaction(new Connection(...));
$t->onUnresolved[] = function($exception) {
    Tracy\Debugger::log($exception);
};

Nette

EXTENSION

extensions:
    ntdb: Minetro\Database\Transaction\DI\Transaction

That's all. You can let nette\di autowired it to your services/presenters., (*16)

NEON

Register as service in your config file., (*17)

services:
    - Minetro\Database\Transaction\Transaction

On multiple connections you have to specific one., (*18)

services:
    - Minetro\Database\Transaction\Transaction(@nette.database.one.connection)
    # or
    - Minetro\Database\Transaction\Transaction(@nette.database.two.connection)

Repository | Presenter

use Minetro\Database\Transaction\Transaction;

class MyRepository {

    function __construct(Connection $connection) {
        $this->transaction = new Transaction($connection);
    }

    // OR

    function __construct(Context $context) {
        $this->transaction = new Transaction($context->getConnection());
    }
}

class MyPresenter {

    public function processSomething() {
        $transaction->transaction(function() {
            // Save one..

            // Make other..

            // Delete from this..

            // Update everything..
        });
    }
}

Development

This package was maintain by these authors., (*19)

, (*20)


Consider to support contributte development team. Also thank you for being used this package., (*21)

The Versions

09/12 2016

dev-master

9999999-dev https://github.com/minetro/ntdb

Nette Database Nested Transaction

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

23/09 2015

0.9.1

0.9.1.0 https://github.com/minetro/ntdb

Nette Database Nested Transaction

  Sources   Download

BSD-3-Clause

The Requires

  • php >= 5.6

 

The Development Requires

28/08 2015

0.9

0.9.0.0 https://github.com/minetro/ntdb

Nette Database Nested Transaction

  Sources   Download

BSD-3-Clause

The Requires

  • php >= 5.5

 

The Development Requires