modify
This commit is contained in:
+12
-6
@@ -6,10 +6,12 @@
|
||||
* Time: 15:40
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database;
|
||||
|
||||
use Database\Traits\QueryTrait;
|
||||
use Exception;
|
||||
use HttpServer\Http\Context;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
@@ -20,14 +22,12 @@ class Db
|
||||
{
|
||||
use QueryTrait;
|
||||
|
||||
private static bool $isActive = false;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function transactionsActive(): bool
|
||||
{
|
||||
return static::$isActive;
|
||||
return Context::getContext('begin:transaction') === true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ class Db
|
||||
*/
|
||||
public static function beginTransaction()
|
||||
{
|
||||
static::$isActive = true;
|
||||
Context::setContext('begin:transaction', true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,10 +43,13 @@ class Db
|
||||
*/
|
||||
public static function commit()
|
||||
{
|
||||
if (!static::transactionsActive()) {
|
||||
return;
|
||||
}
|
||||
$event = Snowflake::app()->getEvent();
|
||||
$event->trigger(Connection::TRANSACTION_COMMIT);
|
||||
$event->offName(Connection::TRANSACTION_COMMIT);
|
||||
static::$isActive = false;
|
||||
Context::deleteId('begin:transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,10 +57,13 @@ class Db
|
||||
*/
|
||||
public static function rollback()
|
||||
{
|
||||
if (!static::transactionsActive()) {
|
||||
return;
|
||||
}
|
||||
$event = Snowflake::app()->getEvent();
|
||||
$event->trigger(Connection::TRANSACTION_ROLLBACK);
|
||||
$event->offName(Connection::TRANSACTION_ROLLBACK);
|
||||
static::$isActive = false;
|
||||
Context::deleteId('begin:transaction');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user