mirror of
https://github.com/dg/dibi.git
synced 2025-08-20 04:41:26 +02:00
added Connection::transaction()
This commit is contained in:
@@ -48,3 +48,24 @@ $conn->query('INSERT INTO [products]', [
|
||||
]);
|
||||
$conn->commit();
|
||||
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
|
||||
|
||||
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->transaction(function () use ($conn) {
|
||||
$conn->query('INSERT INTO [products]', [
|
||||
'title' => 'Test product',
|
||||
]);
|
||||
throw new Exception('my exception');
|
||||
});
|
||||
}, \Throwable::class, 'my exception');
|
||||
|
||||
Assert::same(4, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
|
||||
$conn->transaction(function () use ($conn) {
|
||||
$conn->query('INSERT INTO [products]', [
|
||||
'title' => 'Test product',
|
||||
]);
|
||||
});
|
||||
|
||||
Assert::same(5, (int) $conn->query('SELECT COUNT(*) FROM [products]')->fetchSingle());
|
||||
|
Reference in New Issue
Block a user