-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
153 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Amp\Postgres\Internal; | ||
|
||
use Amp\Postgres\PostgresResult; | ||
use Amp\Postgres\PostgresStatement; | ||
use Amp\Postgres\PostgresTransaction; | ||
use Amp\Sql\Common\NestedTransaction; | ||
|
||
/** | ||
* @internal | ||
* @extends NestedTransaction<PostgresResult, PostgresStatement, PostgresTransaction> | ||
*/ | ||
final class PostgresNestedTransaction extends NestedTransaction implements PostgresTransaction | ||
{ | ||
use PostgresTransactionDelegate; | ||
|
||
protected function getTransaction(): PostgresTransaction | ||
{ | ||
return $this->transaction; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Amp\Postgres\Internal; | ||
|
||
use Amp\Postgres\PostgresResult; | ||
use Amp\Postgres\PostgresStatement; | ||
use Amp\Postgres\PostgresTransaction; | ||
use Amp\Sql\Result; | ||
use Amp\Sql\Statement; | ||
|
||
/** @internal */ | ||
trait PostgresTransactionDelegate | ||
{ | ||
abstract protected function getTransaction(): PostgresTransaction; | ||
|
||
/** | ||
* @param \Closure():void $release | ||
*/ | ||
protected function createStatement(Statement $statement, \Closure $release): PostgresStatement | ||
{ | ||
\assert($statement instanceof PostgresStatement); | ||
return new PostgresPooledStatement($statement, $release); | ||
} | ||
|
||
/** | ||
* @param \Closure():void $release | ||
*/ | ||
protected function createResult(Result $result, \Closure $release): PostgresResult | ||
{ | ||
\assert($result instanceof PostgresResult); | ||
return new PostgresPooledResult($result, $release); | ||
} | ||
|
||
/** | ||
* Changes return type to this library's Result type. | ||
*/ | ||
public function query(string $sql): PostgresResult | ||
{ | ||
return parent::query($sql); | ||
} | ||
|
||
/** | ||
* Changes return type to this library's Statement type. | ||
*/ | ||
public function prepare(string $sql): PostgresStatement | ||
{ | ||
return parent::prepare($sql); | ||
} | ||
|
||
/** | ||
* Changes return type to this library's Result type. | ||
*/ | ||
public function execute(string $sql, array $params = []): PostgresResult | ||
{ | ||
return parent::execute($sql, $params); | ||
} | ||
|
||
/** | ||
* @param non-empty-string $channel | ||
*/ | ||
public function notify(string $channel, string $payload = ""): PostgresResult | ||
{ | ||
return $this->getTransaction()->notify($channel, $payload); | ||
} | ||
|
||
public function quoteString(string $data): string | ||
{ | ||
return $this->getTransaction()->quoteString($data); | ||
} | ||
|
||
public function quoteName(string $name): string | ||
{ | ||
return $this->getTransaction()->quoteName($name); | ||
} | ||
|
||
public function escapeByteA(string $data): string | ||
{ | ||
return $this->transaction->escapeByteA($data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Amp\Postgres; | ||
|
||
use Amp\Sql\Common\NestableTransaction; | ||
use Amp\Sql\Transaction; | ||
use Amp\Sql\TransactionIsolation; | ||
use Amp\Sql\TransactionIsolationLevel; | ||
|
||
/** | ||
* @extends NestableTransaction<PostgresResult, PostgresStatement, PostgresTransaction> | ||
*/ | ||
final class PostgresNestableTransaction extends NestableTransaction implements PostgresLink | ||
{ | ||
protected function createNestedTransaction( | ||
Transaction $transaction, | ||
\Closure $release, | ||
string $identifier, | ||
): Transaction { | ||
return new Internal\PostgresNestedTransaction($transaction, $release, $identifier); | ||
} | ||
|
||
/** | ||
* Changes return type to this library's Transaction type. | ||
*/ | ||
public function beginTransaction( | ||
TransactionIsolation $isolation = TransactionIsolationLevel::Committed | ||
): PostgresTransaction { | ||
return parent::beginTransaction($isolation); | ||
} | ||
|
||
public function quoteString(string $data): string | ||
{ | ||
return $this->transaction->quoteString($data); | ||
} | ||
|
||
public function quoteName(string $name): string | ||
{ | ||
return $this->transaction->quoteName($name); | ||
} | ||
|
||
public function escapeByteA(string $data): string | ||
{ | ||
return $this->transaction->escapeByteA($data); | ||
} | ||
} |