mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 13:17:58 +02:00
Connection::transaction(): pass self as a callback argument
This commit is contained in:
committed by
David Grudl
parent
771e846a62
commit
7049949b14
@@ -409,7 +409,7 @@ class Connection implements IConnection
|
|||||||
{
|
{
|
||||||
$this->begin();
|
$this->begin();
|
||||||
try {
|
try {
|
||||||
$res = $callback();
|
$res = $callback($this);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->rollback();
|
$this->rollback();
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@@ -52,8 +52,8 @@ Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSing
|
|||||||
|
|
||||||
|
|
||||||
Assert::exception(function () use ($conn) {
|
Assert::exception(function () use ($conn) {
|
||||||
$conn->transaction(function () use ($conn) {
|
$conn->transaction(function (Dibi\Connection $connection) {
|
||||||
$conn->query('INSERT INTO [products]', [
|
$connection->query('INSERT INTO [products]', [
|
||||||
'title' => 'Test product',
|
'title' => 'Test product',
|
||||||
]);
|
]);
|
||||||
throw new Exception('my exception');
|
throw new Exception('my exception');
|
||||||
@@ -62,8 +62,8 @@ Assert::exception(function () use ($conn) {
|
|||||||
|
|
||||||
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||||
|
|
||||||
$conn->transaction(function () use ($conn) {
|
$conn->transaction(function (Dibi\Connection $connection) {
|
||||||
$conn->query('INSERT INTO [products]', [
|
$connection->query('INSERT INTO [products]', [
|
||||||
'title' => 'Test product',
|
'title' => 'Test product',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user