diff --git a/composer.json b/composer.json
index ad9b210..d34c7e0 100644
--- a/composer.json
+++ b/composer.json
@@ -22,8 +22,8 @@
"php": ">=8.1",
"amphp/amp": "^3",
"amphp/pipeline": "^1",
- "amphp/sql": "^2-beta.6",
- "amphp/sql-common": "^2-beta.9"
+ "amphp/sql": "2.x-dev",
+ "amphp/sql-common": "2.x-dev"
},
"require-dev": {
"ext-pgsql": "*",
diff --git a/examples/5-bytea.php b/examples/5-bytea.php
index c0c8e20..d1911c9 100644
--- a/examples/5-bytea.php
+++ b/examples/5-bytea.php
@@ -3,7 +3,7 @@
require dirname(__DIR__) . '/vendor/autoload.php';
-use Amp\Postgres\ByteA;
+use Amp\Postgres\PostgresByteA;
use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresConnectionPool;
@@ -18,11 +18,11 @@
$statement = $transaction->prepare('INSERT INTO test VALUES (?)');
-$statement->execute([new ByteA($a = random_bytes(10))]);
-$statement->execute([new ByteA($b = random_bytes(10))]);
-$statement->execute([new ByteA($c = random_bytes(10))]);
+$statement->execute([new PostgresByteA($a = random_bytes(10))]);
+$statement->execute([new PostgresByteA($b = random_bytes(10))]);
+$statement->execute([new PostgresByteA($c = random_bytes(10))]);
-$result = $transaction->execute('SELECT * FROM test WHERE value = :value', ['value' => new ByteA($a)]);
+$result = $transaction->execute('SELECT * FROM test WHERE value = :value', ['value' => new PostgresByteA($a)]);
foreach ($result as $row) {
assert($row['value'] === $a);
diff --git a/psalm.xml b/psalm.xml
index 6aa023a..99f52e0 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -27,6 +27,12 @@
+
+
+
+
+
+
diff --git a/src/Internal/AbstractHandle.php b/src/Internal/AbstractHandle.php
index 277777c..8da013a 100644
--- a/src/Internal/AbstractHandle.php
+++ b/src/Internal/AbstractHandle.php
@@ -6,9 +6,9 @@
use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Pipeline\Queue;
-use Amp\Postgres\ByteA;
+use Amp\Postgres\PostgresByteA;
use Amp\Postgres\PostgresConfig;
-use Amp\Sql\ConnectionException;
+use Amp\Sql\SqlConnectionException;
use Revolt\EventLoop;
/**
@@ -75,14 +75,14 @@ protected static function shutdown(
?\Throwable $exception = null,
): void {
if (!empty($listeners)) {
- $exception ??= new ConnectionException("The connection was closed");
+ $exception ??= new SqlConnectionException("The connection was closed");
foreach ($listeners as $listener) {
$listener->error($exception);
}
$listeners = [];
}
- $pendingOperation?->error($exception ?? new ConnectionException("The connection was closed"));
+ $pendingOperation?->error($exception ?? new SqlConnectionException("The connection was closed"));
$pendingOperation = null;
if (!$onClose->isComplete()) {
@@ -93,7 +93,7 @@ protected static function shutdown(
protected function escapeParams(array $params): array
{
return \array_map(fn (mixed $param) => match (true) {
- $param instanceof ByteA => $this->escapeByteA($param->getData()),
+ $param instanceof PostgresByteA => $this->escapeByteA($param->getData()),
\is_array($param) => $this->escapeParams($param),
default => $param,
}, $params);
diff --git a/src/Internal/ArrayParser.php b/src/Internal/ArrayParser.php
index 9e81a1e..35183e6 100644
--- a/src/Internal/ArrayParser.php
+++ b/src/Internal/ArrayParser.php
@@ -4,7 +4,7 @@
use Amp\ForbidCloning;
use Amp\ForbidSerialization;
-use Amp\Postgres\ParseException;
+use Amp\Postgres\PostgresParseException;
/**
* @internal
@@ -21,7 +21,7 @@ final class ArrayParser
*
* @return list Parsed column data.
*
- * @throws ParseException
+ * @throws PostgresParseException
*/
public static function parse(string $data, \Closure $cast, string $delimiter = ','): array
{
@@ -31,7 +31,7 @@ public static function parse(string $data, \Closure $cast, string $delimiter = '
$data = \iterator_to_array($parser, false);
if ($parser->getReturn() !== '') {
- throw new ParseException("Data left in buffer after parsing");
+ throw new PostgresParseException("Data left in buffer after parsing");
}
return $data;
@@ -52,23 +52,23 @@ private function __construct(
/**
* Recursive generator parser yielding array values.
*
- * @throws ParseException
+ * @throws PostgresParseException
*/
private function parser(): \Generator
{
if ($this->data === '') {
- throw new ParseException("Unexpected end of data");
+ throw new PostgresParseException("Unexpected end of data");
}
if ($this->data[0] !== '{') {
- throw new ParseException("Missing opening bracket");
+ throw new PostgresParseException("Missing opening bracket");
}
$this->data = \ltrim(\substr($this->data, 1));
do {
if ($this->data === '') {
- throw new ParseException("Unexpected end of data");
+ throw new PostgresParseException("Unexpected end of data");
}
if ($this->data[0] === '}') { // Empty array
@@ -96,7 +96,7 @@ private function parser(): \Generator
}
if (!isset($this->data[$position])) {
- throw new ParseException("Could not find matching quote in quoted value");
+ throw new PostgresParseException("Could not find matching quote in quoted value");
}
$yield = \stripslashes(\substr($this->data, 1, $position - 1));
@@ -129,20 +129,20 @@ private function parser(): \Generator
*
* @return string First non-whitespace character after given position.
*
- * @throws ParseException
+ * @throws PostgresParseException
*/
private function trim(int $position): string
{
$this->data = \ltrim(\substr($this->data, $position));
if ($this->data === '') {
- throw new ParseException("Unexpected end of data");
+ throw new PostgresParseException("Unexpected end of data");
}
$end = $this->data[0];
if ($end !== $this->delimiter && $end !== '}') {
- throw new ParseException("Invalid delimiter");
+ throw new PostgresParseException("Invalid delimiter");
}
$this->data = \ltrim(\substr($this->data, 1));
diff --git a/src/Internal/PgSqlHandle.php b/src/Internal/PgSqlHandle.php
index c565c65..f253715 100644
--- a/src/Internal/PgSqlHandle.php
+++ b/src/Internal/PgSqlHandle.php
@@ -8,12 +8,12 @@
use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresListener;
use Amp\Postgres\PostgresNotification;
+use Amp\Postgres\PostgresQueryError;
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
-use Amp\Postgres\QueryExecutionError;
-use Amp\Sql\ConnectionException;
-use Amp\Sql\QueryError;
+use Amp\Sql\SqlConnectionException;
use Amp\Sql\SqlException;
+use Amp\Sql\SqlQueryError;
use Revolt\EventLoop;
use function Amp\async;
@@ -88,11 +88,11 @@ public function __construct(
try {
if (\pg_connection_status($handle) !== \PGSQL_CONNECTION_OK) {
- throw new ConnectionException("The connection closed during the operation");
+ throw new SqlConnectionException("The connection closed during the operation");
}
if (!\pg_consume_input($handle)) {
- throw new ConnectionException(\pg_last_error($handle));
+ throw new SqlConnectionException(\pg_last_error($handle));
}
while ($result = \pg_get_notify($handle, \PGSQL_ASSOC)) {
@@ -120,7 +120,7 @@ public function __construct(
if (empty($listeners)) {
EventLoop::unreference($watcher);
}
- } catch (ConnectionException $exception) {
+ } catch (SqlConnectionException $exception) {
$handle = null; // Marks connection as dead.
EventLoop::disable($watcher);
@@ -152,9 +152,9 @@ public function __construct(
EventLoop::disable($watcher);
if ($flush === false) {
- throw new ConnectionException(\pg_last_error($handle));
+ throw new SqlConnectionException(\pg_last_error($handle));
}
- } catch (ConnectionException $exception) {
+ } catch (SqlConnectionException $exception) {
$handle = null; // Marks connection as dead.
EventLoop::disable($watcher);
@@ -193,7 +193,7 @@ private static function fetchTypes(\PgSql\Connection $handle): array
private static function getErrorHandler(): \Closure
{
return self::$errorHandler ??= static function (int $code, string $message): never {
- throw new ConnectionException($message, $code);
+ throw new SqlConnectionException($message, $code);
};
}
@@ -227,7 +227,7 @@ private function send(\Closure $function, mixed ...$args): mixed
}
if ($this->handle === null) {
- throw new ConnectionException("The connection to the database has been closed");
+ throw new SqlConnectionException("The connection to the database has been closed");
}
while ($result = \pg_get_result($this->handle)) {
@@ -255,7 +255,7 @@ private function send(\Closure $function, mixed ...$args): mixed
* @param string $sql Query SQL.
*
* @throws SqlException
- * @throws QueryError
+ * @throws SqlQueryError
*/
private function createResult(\PgSql\Result $result, string $sql): PostgresResult
{
@@ -265,7 +265,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul
switch (\pg_result_status($result)) {
case \PGSQL_EMPTY_QUERY:
- throw new QueryError("Empty query string");
+ throw new SqlQueryError("Empty query string");
case \PGSQL_COMMAND_OK:
return new PostgresCommandResult(
@@ -290,7 +290,7 @@ private function createResult(\PgSql\Result $result, string $sql): PostgresResul
}
} finally {
\restore_error_handler();
- throw new QueryExecutionError($message, $diagnostics, $sql);
+ throw new PostgresQueryError($message, $diagnostics, $sql);
}
case \PGSQL_BAD_RESPONSE:
@@ -428,7 +428,7 @@ public function prepare(string $sql): PostgresStatement
foreach (self::DIAGNOSTIC_CODES as $fieldCode => $description) {
$diagnostics[$description] = \pg_result_error_field($result, $fieldCode);
}
- throw new QueryExecutionError(\pg_result_error($result), $diagnostics, $sql);
+ throw new PostgresQueryError(\pg_result_error($result), $diagnostics, $sql);
case \PGSQL_BAD_RESPONSE:
throw new SqlException(\pg_result_error($result));
@@ -465,7 +465,7 @@ public function notify(string $channel, string $payload = ""): PostgresResult
public function listen(string $channel): PostgresListener
{
if (isset($this->listeners[$channel])) {
- throw new QueryError(\sprintf("Already listening on channel '%s'", $channel));
+ throw new SqlQueryError(\sprintf("Already listening on channel '%s'", $channel));
}
$this->listeners[$channel] = $source = new Queue();
diff --git a/src/Internal/PgSqlResultIterator.php b/src/Internal/PgSqlResultIterator.php
index d3e414f..a62fbd0 100644
--- a/src/Internal/PgSqlResultIterator.php
+++ b/src/Internal/PgSqlResultIterator.php
@@ -4,7 +4,7 @@
use Amp\ForbidCloning;
use Amp\ForbidSerialization;
-use Amp\Postgres\ParseException;
+use Amp\Postgres\PostgresParseException;
use Amp\Postgres\PostgresResult;
use Amp\Sql\SqlException;
@@ -71,7 +71,7 @@ private function getIterator(): \Iterator
*
* @return list|bool|int|float|string|null
*
- * @throws ParseException
+ * @throws PostgresParseException
*/
private function cast(int $oid, ?string $value): array|bool|int|float|string|null
{
diff --git a/src/Internal/PostgresCommandResult.php b/src/Internal/PostgresCommandResult.php
index 8c34ed5..3784ec6 100644
--- a/src/Internal/PostgresCommandResult.php
+++ b/src/Internal/PostgresCommandResult.php
@@ -3,14 +3,14 @@
namespace Amp\Postgres\Internal;
use Amp\Postgres\PostgresResult;
-use Amp\Sql\Common\CommandResult;
+use Amp\Sql\Common\SqlCommandResult;
/**
* @internal
* @psalm-import-type TFieldType from PostgresResult
- * @extends CommandResult
+ * @extends SqlCommandResult
*/
-final class PostgresCommandResult extends CommandResult implements PostgresResult
+final class PostgresCommandResult extends SqlCommandResult implements PostgresResult
{
/**
* Changes return type to this library's Result type.
diff --git a/src/Internal/PostgresConnectionStatement.php b/src/Internal/PostgresConnectionStatement.php
index 6ee32ef..2d0f323 100644
--- a/src/Internal/PostgresConnectionStatement.php
+++ b/src/Internal/PostgresConnectionStatement.php
@@ -5,8 +5,8 @@
use Amp\DeferredFuture;
use Amp\ForbidCloning;
use Amp\ForbidSerialization;
+use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
-use Amp\Sql\Result;
use Amp\Sql\SqlException;
/** @internal */
@@ -67,7 +67,7 @@ public function getLastUsedAt(): int
return $this->lastUsedAt;
}
- public function execute(array $params = []): Result
+ public function execute(array $params = []): PostgresResult
{
if ($this->isClosed()) {
throw new SqlException('The statement has been closed or the connection went away');
diff --git a/src/Internal/PostgresConnectionTransaction.php b/src/Internal/PostgresConnectionTransaction.php
index 3a4fefc..0d8ec1d 100644
--- a/src/Internal/PostgresConnectionTransaction.php
+++ b/src/Internal/PostgresConnectionTransaction.php
@@ -6,30 +6,30 @@
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
use Amp\Postgres\PostgresTransaction;
-use Amp\Sql\Common\ConnectionTransaction;
-use Amp\Sql\Common\NestableTransactionExecutor;
-use Amp\Sql\Transaction;
-use Amp\Sql\TransactionIsolation;
+use Amp\Sql\Common\SqlConnectionTransaction;
+use Amp\Sql\Common\SqlNestableTransactionExecutor;
+use Amp\Sql\SqlTransaction;
+use Amp\Sql\SqlTransactionIsolation;
/**
* @internal
- * @extends ConnectionTransaction
+ * @extends SqlConnectionTransaction
*/
-final class PostgresConnectionTransaction extends ConnectionTransaction implements PostgresTransaction
+final class PostgresConnectionTransaction extends SqlConnectionTransaction implements PostgresTransaction
{
use PostgresTransactionDelegate;
public function __construct(
private readonly PostgresHandle $handle,
\Closure $release,
- TransactionIsolation $isolation
+ SqlTransactionIsolation $isolation
) {
parent::__construct($handle, $release, $isolation);
}
protected function createNestedTransaction(
- Transaction $transaction,
- NestableTransactionExecutor $executor,
+ SqlTransaction $transaction,
+ SqlNestableTransactionExecutor $executor,
string $identifier,
\Closure $release,
): PostgresTransaction {
diff --git a/src/Internal/PostgresHandle.php b/src/Internal/PostgresHandle.php
index eb3b634..17cd415 100644
--- a/src/Internal/PostgresHandle.php
+++ b/src/Internal/PostgresHandle.php
@@ -7,13 +7,13 @@
use Amp\Postgres\PostgresListener;
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
-use Amp\Sql\Common\NestableTransactionExecutor;
+use Amp\Sql\Common\SqlNestableTransactionExecutor;
/**
* @internal
- * @extends NestableTransactionExecutor
+ * @extends SqlNestableTransactionExecutor
*/
-interface PostgresHandle extends PostgresExecutor, NestableTransactionExecutor
+interface PostgresHandle extends PostgresExecutor, SqlNestableTransactionExecutor
{
public const STATEMENT_NAME_PREFIX = "amp_";
diff --git a/src/Internal/PostgresHandleConnection.php b/src/Internal/PostgresHandleConnection.php
index e46d03d..5e8bbe0 100644
--- a/src/Internal/PostgresHandleConnection.php
+++ b/src/Internal/PostgresHandleConnection.php
@@ -13,9 +13,9 @@
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
use Amp\Postgres\PostgresTransaction;
-use Amp\Sql\ConnectionException;
-use Amp\Sql\TransactionIsolation;
-use Amp\Sql\TransactionIsolationLevel;
+use Amp\Sql\SqlConnectionException;
+use Amp\Sql\SqlTransactionIsolation;
+use Amp\Sql\SqlTransactionIsolationLevel;
/** @internal */
abstract class PostgresHandleConnection implements PostgresConnection
@@ -26,10 +26,10 @@ abstract class PostgresHandleConnection implements PostgresConnection
/** @var DeferredFuture|null Used to only allow one transaction at a time. */
private ?DeferredFuture $busy = null;
- private TransactionIsolation $transactionIsolation = TransactionIsolationLevel::Committed;
+ private SqlTransactionIsolation $transactionIsolation = SqlTransactionIsolationLevel::Committed;
/**
- * @throws ConnectionException
+ * @throws SqlConnectionException
*/
abstract public static function connect(
PostgresConfig $config,
@@ -140,12 +140,12 @@ final public function beginTransaction(): PostgresTransaction
);
}
- final public function getTransactionIsolation(): TransactionIsolation
+ final public function getTransactionIsolation(): SqlTransactionIsolation
{
return $this->transactionIsolation;
}
- final public function setTransactionIsolation(TransactionIsolation $isolation): void
+ final public function setTransactionIsolation(SqlTransactionIsolation $isolation): void
{
$this->transactionIsolation = $isolation;
}
diff --git a/src/Internal/PostgresNestedTransaction.php b/src/Internal/PostgresNestedTransaction.php
index bdd631b..db0a0ff 100644
--- a/src/Internal/PostgresNestedTransaction.php
+++ b/src/Internal/PostgresNestedTransaction.php
@@ -6,15 +6,15 @@
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
use Amp\Postgres\PostgresTransaction;
-use Amp\Sql\Common\NestableTransactionExecutor;
-use Amp\Sql\Common\NestedTransaction;
-use Amp\Sql\Transaction;
+use Amp\Sql\Common\SqlNestableTransactionExecutor;
+use Amp\Sql\Common\SqlNestedTransaction;
+use Amp\Sql\SqlTransaction;
/**
* @internal
- * @extends NestedTransaction
+ * @extends SqlNestedTransaction
*/
-final class PostgresNestedTransaction extends NestedTransaction implements PostgresTransaction
+final class PostgresNestedTransaction extends SqlNestedTransaction implements PostgresTransaction
{
use PostgresTransactionDelegate;
@@ -37,8 +37,8 @@ protected function getExecutor(): PostgresExecutor
}
protected function createNestedTransaction(
- Transaction $transaction,
- NestableTransactionExecutor $executor,
+ SqlTransaction $transaction,
+ SqlNestableTransactionExecutor $executor,
string $identifier,
\Closure $release,
): PostgresTransaction {
diff --git a/src/Internal/PostgresPooledResult.php b/src/Internal/PostgresPooledResult.php
index be9258a..c24f65d 100644
--- a/src/Internal/PostgresPooledResult.php
+++ b/src/Internal/PostgresPooledResult.php
@@ -3,17 +3,17 @@
namespace Amp\Postgres\Internal;
use Amp\Postgres\PostgresResult;
-use Amp\Sql\Common\PooledResult;
-use Amp\Sql\Result;
+use Amp\Sql\Common\SqlPooledResult;
+use Amp\Sql\SqlResult;
/**
* @internal
* @psalm-import-type TFieldType from PostgresResult
- * @extends PooledResult
+ * @extends SqlPooledResult
*/
-final class PostgresPooledResult extends PooledResult implements PostgresResult
+final class PostgresPooledResult extends SqlPooledResult implements PostgresResult
{
- protected static function newInstanceFrom(Result $result, \Closure $release): self
+ protected static function newInstanceFrom(SqlResult $result, \Closure $release): self
{
\assert($result instanceof PostgresResult);
return new self($result, $release);
diff --git a/src/Internal/PostgresPooledStatement.php b/src/Internal/PostgresPooledStatement.php
index 8036a7c..a186773 100644
--- a/src/Internal/PostgresPooledStatement.php
+++ b/src/Internal/PostgresPooledStatement.php
@@ -4,16 +4,16 @@
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
-use Amp\Sql\Common\PooledStatement;
-use Amp\Sql\Result;
+use Amp\Sql\Common\SqlPooledStatement;
+use Amp\Sql\SqlResult;
/**
* @internal
- * @extends PooledStatement
+ * @extends SqlPooledStatement
*/
-final class PostgresPooledStatement extends PooledStatement implements PostgresStatement
+final class PostgresPooledStatement extends SqlPooledStatement implements PostgresStatement
{
- protected function createResult(Result $result, \Closure $release): PostgresResult
+ protected function createResult(SqlResult $result, \Closure $release): PostgresResult
{
\assert($result instanceof PostgresResult);
return new PostgresPooledResult($result, $release);
diff --git a/src/Internal/PostgresPooledTransaction.php b/src/Internal/PostgresPooledTransaction.php
index 1a162a2..96498f0 100644
--- a/src/Internal/PostgresPooledTransaction.php
+++ b/src/Internal/PostgresPooledTransaction.php
@@ -6,14 +6,14 @@
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
use Amp\Postgres\PostgresTransaction;
-use Amp\Sql\Common\PooledTransaction;
-use Amp\Sql\Transaction;
+use Amp\Sql\Common\SqlPooledTransaction;
+use Amp\Sql\SqlTransaction;
/**
* @internal
- * @extends PooledTransaction
+ * @extends SqlPooledTransaction
*/
-final class PostgresPooledTransaction extends PooledTransaction implements PostgresTransaction
+final class PostgresPooledTransaction extends SqlPooledTransaction implements PostgresTransaction
{
use PostgresTransactionDelegate;
@@ -30,7 +30,7 @@ protected function getExecutor(): PostgresExecutor
return $this->transaction;
}
- protected function createTransaction(Transaction $transaction, \Closure $release): PostgresTransaction
+ protected function createTransaction(SqlTransaction $transaction, \Closure $release): PostgresTransaction
{
\assert($transaction instanceof PostgresTransaction);
return new PostgresPooledTransaction($transaction, $release);
diff --git a/src/Internal/PostgresStatementPool.php b/src/Internal/PostgresStatementPool.php
index fd4c68c..cb79f68 100644
--- a/src/Internal/PostgresStatementPool.php
+++ b/src/Internal/PostgresStatementPool.php
@@ -6,8 +6,8 @@
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
use Amp\Postgres\PostgresTransaction;
-use Amp\Sql\Common\StatementPool as SqlStatementPool;
-use Amp\Sql\Result as SqlResult;
+use Amp\Sql\Common\SqlStatementPool as SqlStatementPool;
+use Amp\Sql\SqlResult as SqlResult;
/**
* @internal
diff --git a/src/Internal/PostgresTransactionDelegate.php b/src/Internal/PostgresTransactionDelegate.php
index fcaaa1e..bd03789 100644
--- a/src/Internal/PostgresTransactionDelegate.php
+++ b/src/Internal/PostgresTransactionDelegate.php
@@ -6,8 +6,8 @@
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
use Amp\Postgres\PostgresTransaction;
-use Amp\Sql\Result;
-use Amp\Sql\Statement;
+use Amp\Sql\SqlResult;
+use Amp\Sql\SqlStatement;
/** @internal */
trait PostgresTransactionDelegate
@@ -18,7 +18,7 @@ abstract protected function getExecutor(): PostgresExecutor;
* @param \Closure():void $release
*/
protected function createStatement(
- Statement $statement,
+ SqlStatement $statement,
\Closure $release,
?\Closure $awaitBusyResource = null,
): PostgresStatement {
@@ -29,7 +29,7 @@ protected function createStatement(
/**
* @param \Closure():void $release
*/
- protected function createResult(Result $result, \Closure $release): PostgresResult
+ protected function createResult(SqlResult $result, \Closure $release): PostgresResult
{
\assert($result instanceof PostgresResult);
return new PostgresPooledResult($result, $release);
diff --git a/src/Internal/PqHandle.php b/src/Internal/PqHandle.php
index 29f76ff..896a723 100644
--- a/src/Internal/PqHandle.php
+++ b/src/Internal/PqHandle.php
@@ -8,12 +8,12 @@
use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresListener;
use Amp\Postgres\PostgresNotification;
+use Amp\Postgres\PostgresQueryError;
use Amp\Postgres\PostgresResult;
use Amp\Postgres\PostgresStatement;
-use Amp\Postgres\QueryExecutionError;
-use Amp\Sql\ConnectionException;
-use Amp\Sql\QueryError;
+use Amp\Sql\SqlConnectionException;
use Amp\Sql\SqlException;
+use Amp\Sql\SqlQueryError;
use pq;
use Revolt\EventLoop;
use function Amp\async;
@@ -49,13 +49,13 @@ public function __construct(pq\Connection $handle, PostgresConfig $config)
try {
if ($handle->status !== pq\Connection::OK) {
- throw new ConnectionException("The connection closed during the operation");
+ throw new SqlConnectionException("The connection closed during the operation");
}
if ($handle->poll() === pq\Connection::POLLING_FAILED) {
- throw new ConnectionException($handle->errorMessage);
+ throw new SqlConnectionException($handle->errorMessage);
}
- } catch (ConnectionException $exception) {
+ } catch (SqlConnectionException $exception) {
$handle = null; // Marks connection as dead.
EventLoop::disable($watcher);
@@ -91,7 +91,7 @@ public function __construct(pq\Connection $handle, PostgresConfig $config)
return; // Not finished sending data, continue polling for writability.
}
} catch (pq\Exception $exception) {
- $exception = new ConnectionException("Flushing the connection failed", 0, $exception);
+ $exception = new SqlConnectionException("Flushing the connection failed", 0, $exception);
$handle = null; // Marks connection as dead.
self::shutdown($listeners, $deferred, $onClose, $exception);
@@ -135,7 +135,7 @@ private function send(?string $sql, \Closure $method, mixed ...$args): mixed
}
if (!$this->handle) {
- throw new ConnectionException("The connection to the database has been closed");
+ throw new SqlConnectionException("The connection to the database has been closed");
}
try {
@@ -180,12 +180,12 @@ private function send(?string $sql, \Closure $method, mixed ...$args): mixed
private function makeResult(pq\Result $result, ?string $sql): PostgresResult
{
if (!$this->handle) {
- throw new ConnectionException("Connection closed");
+ throw new SqlConnectionException("Connection closed");
}
switch ($result->status) {
case pq\Result::EMPTY_QUERY:
- throw new QueryError("Empty query string");
+ throw new SqlQueryError("Empty query string");
case pq\Result::COMMAND_OK:
return new PostgresCommandResult(
@@ -209,7 +209,7 @@ private function makeResult(pq\Result $result, ?string $sql): PostgresResult
while ($this->handle->busy && $this->handle->getResult()) {
// Clear all outstanding result rows from the connection
}
- throw new QueryExecutionError($result->errorMessage, $result->diag, $sql ?? '');
+ throw new PostgresQueryError($result->errorMessage, $result->diag, $sql ?? '');
case pq\Result::BAD_RESPONSE:
$this->close();
@@ -227,7 +227,7 @@ private function makeResult(pq\Result $result, ?string $sql): PostgresResult
private function fetchNextResult(?string $sql): ?PostgresResult
{
if (!$this->handle) {
- throw new ConnectionException("Connection closed");
+ throw new SqlConnectionException("Connection closed");
}
if (!$this->handle->busy && ($next = $this->handle->getResult()) instanceof pq\Result) {
@@ -240,7 +240,7 @@ private function fetchNextResult(?string $sql): ?PostgresResult
private function fetch(?string $sql): ?pq\Result
{
if (!$this->handle) {
- throw new ConnectionException("Connection closed");
+ throw new SqlConnectionException("Connection closed");
}
if (!$this->handle->busy) { // Results buffered.
@@ -257,7 +257,7 @@ private function fetch(?string $sql): ?pq\Result
}
if (!$result) {
- throw new ConnectionException("Connection closed");
+ throw new SqlConnectionException("Connection closed");
}
switch ($result->status) {
@@ -430,7 +430,7 @@ public function listen(string $channel): PostgresListener
}
if (isset($this->listeners[$channel])) {
- throw new QueryError(\sprintf("Already listening on channel '%s'", $channel));
+ throw new SqlQueryError(\sprintf("Already listening on channel '%s'", $channel));
}
$this->listeners[$channel] = $source = new Queue();
diff --git a/src/PgSqlConnection.php b/src/PgSqlConnection.php
index d451a3c..30ece36 100644
--- a/src/PgSqlConnection.php
+++ b/src/PgSqlConnection.php
@@ -4,7 +4,7 @@
use Amp\Cancellation;
use Amp\DeferredFuture;
-use Amp\Sql\ConnectionException;
+use Amp\Sql\SqlConnectionException;
use Revolt\EventLoop;
final class PgSqlConnection extends Internal\PostgresHandleConnection implements PostgresConnection
@@ -21,15 +21,15 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati
} // @codeCoverageIgnoreEnd
if (!$connection = \pg_connect($config->getConnectionString(), \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW)) {
- throw new ConnectionException("Failed to create connection resource");
+ throw new SqlConnectionException("Failed to create connection resource");
}
if (\pg_connection_status($connection) === \PGSQL_CONNECTION_BAD) {
- throw new ConnectionException(\pg_last_error($connection));
+ throw new SqlConnectionException(\pg_last_error($connection));
}
if (!$socket = \pg_socket($connection)) {
- throw new ConnectionException("Failed to access connection socket");
+ throw new SqlConnectionException("Failed to access connection socket");
}
$hash = \sha1($config->getHost() . $config->getPort() . $config->getUser());
@@ -54,7 +54,7 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati
return; // Connection still reading or writing, so return and leave callback enabled.
case \PGSQL_POLLING_FAILED:
- $deferred->error(new ConnectionException(\pg_last_error($connection)));
+ $deferred->error(new SqlConnectionException(\pg_last_error($connection)));
break;
case \PGSQL_POLLING_OK:
@@ -62,7 +62,7 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati
break;
default:
- $deferred->error(new ConnectionException('Unexpected connection status value: ' . $result));
+ $deferred->error(new SqlConnectionException('Unexpected connection status value: ' . $result));
break;
}
diff --git a/src/ByteA.php b/src/PostgresByteA.php
similarity index 89%
rename from src/ByteA.php
rename to src/PostgresByteA.php
index 02b44cb..8025616 100644
--- a/src/ByteA.php
+++ b/src/PostgresByteA.php
@@ -2,7 +2,7 @@
namespace Amp\Postgres;
-final class ByteA
+final class PostgresByteA
{
public function __construct(
private readonly string $data,
diff --git a/src/PostgresConnection.php b/src/PostgresConnection.php
index 67742dc..d175980 100644
--- a/src/PostgresConnection.php
+++ b/src/PostgresConnection.php
@@ -2,15 +2,15 @@
namespace Amp\Postgres;
-use Amp\Sql\Connection;
-use Amp\Sql\ConnectionException;
-use Amp\Sql\QueryError;
+use Amp\Sql\SqlConnection;
+use Amp\Sql\SqlConnectionException;
use Amp\Sql\SqlException;
+use Amp\Sql\SqlQueryError;
/**
- * @extends Connection
+ * @extends SqlConnection
*/
-interface PostgresConnection extends PostgresLink, Connection
+interface PostgresConnection extends PostgresLink, SqlConnection
{
/**
* @return PostgresConfig Config object specific to this library.
@@ -21,8 +21,8 @@ public function getConfig(): PostgresConfig;
* @param non-empty-string $channel Channel name.
*
* @throws SqlException If the operation fails due to unexpected condition.
- * @throws ConnectionException If the connection to the database is lost.
- * @throws QueryError If the operation fails due to an error in the query (such as a syntax error).
+ * @throws SqlConnectionException If the connection to the database is lost.
+ * @throws SqlQueryError If the operation fails due to an error in the query (such as a syntax error).
*/
public function listen(string $channel): PostgresListener;
}
diff --git a/src/PostgresConnectionPool.php b/src/PostgresConnectionPool.php
index 7a9296a..724f8b2 100644
--- a/src/PostgresConnectionPool.php
+++ b/src/PostgresConnectionPool.php
@@ -3,17 +3,17 @@
namespace Amp\Postgres;
use Amp\Future;
-use Amp\Sql\Common\ConnectionPool;
-use Amp\Sql\Result;
+use Amp\Sql\Common\SqlCommonConnectionPool;
use Amp\Sql\SqlConnector;
-use Amp\Sql\Statement;
-use Amp\Sql\Transaction;
+use Amp\Sql\SqlResult;
+use Amp\Sql\SqlStatement;
+use Amp\Sql\SqlTransaction;
use function Amp\async;
/**
- * @extends ConnectionPool
+ * @extends SqlCommonConnectionPool
*/
-final class PostgresConnectionPool extends ConnectionPool implements PostgresConnection
+final class PostgresConnectionPool extends SqlCommonConnectionPool implements PostgresConnection
{
/** @var Future|null Connection used for notification listening. */
private Future|null $listeningConnection = null;
@@ -40,13 +40,13 @@ public function __construct(
/**
* @param \Closure():void $release
*/
- protected function createStatement(Statement $statement, \Closure $release): PostgresStatement
+ protected function createStatement(SqlStatement $statement, \Closure $release): PostgresStatement
{
\assert($statement instanceof PostgresStatement);
return new Internal\PostgresPooledStatement($statement, $release);
}
- protected function createResult(Result $result, \Closure $release): PostgresResult
+ protected function createResult(SqlResult $result, \Closure $release): PostgresResult
{
\assert($result instanceof PostgresResult);
return new Internal\PostgresPooledResult($result, $release);
@@ -57,7 +57,7 @@ protected function createStatementPool(string $sql, \Closure $prepare): Postgres
return new Internal\PostgresStatementPool($this, $sql, $prepare);
}
- protected function createTransaction(Transaction $transaction, \Closure $release): PostgresTransaction
+ protected function createTransaction(SqlTransaction $transaction, \Closure $release): PostgresTransaction
{
\assert($transaction instanceof PostgresTransaction);
return new Internal\PostgresPooledTransaction($transaction, $release);
diff --git a/src/PostgresExecutor.php b/src/PostgresExecutor.php
index 2d4f9af..5ffed12 100644
--- a/src/PostgresExecutor.php
+++ b/src/PostgresExecutor.php
@@ -2,14 +2,14 @@
namespace Amp\Postgres;
-use Amp\Sql\ConnectionException;
-use Amp\Sql\Executor;
+use Amp\Sql\SqlConnectionException;
use Amp\Sql\SqlException;
+use Amp\Sql\SqlExecutor;
/**
- * @extends Executor
+ * @extends SqlExecutor
*/
-interface PostgresExecutor extends Executor
+interface PostgresExecutor extends SqlExecutor
{
/**
* @return PostgresResult Result object specific to this library.
@@ -31,7 +31,7 @@ public function execute(string $sql, array $params = []): PostgresResult;
* @param string $payload Notification payload.
*
* @throws SqlException If the operation fails due to unexpected condition.
- * @throws ConnectionException If the connection to the database is lost.
+ * @throws SqlConnectionException If the connection to the database is lost.
*/
public function notify(string $channel, string $payload = ""): PostgresResult;
diff --git a/src/PostgresLink.php b/src/PostgresLink.php
index 361964f..b054df9 100644
--- a/src/PostgresLink.php
+++ b/src/PostgresLink.php
@@ -2,12 +2,12 @@
namespace Amp\Postgres;
-use Amp\Sql\Link;
+use Amp\Sql\SqlLink;
/**
- * @extends Link
+ * @extends SqlLink
*/
-interface PostgresLink extends PostgresExecutor, Link
+interface PostgresLink extends PostgresExecutor, SqlLink
{
/**
* @return PostgresTransaction Transaction object specific to this library.
diff --git a/src/ParseException.php b/src/PostgresParseException.php
similarity index 84%
rename from src/ParseException.php
rename to src/PostgresParseException.php
index 9326aba..44024f2 100644
--- a/src/ParseException.php
+++ b/src/PostgresParseException.php
@@ -4,7 +4,7 @@
use Amp\Sql\SqlException;
-final class ParseException extends SqlException
+final class PostgresParseException extends SqlException
{
public function __construct(string $message = '')
{
diff --git a/src/QueryExecutionError.php b/src/PostgresQueryError.php
similarity index 87%
rename from src/QueryExecutionError.php
rename to src/PostgresQueryError.php
index 0944ac9..83e1ec1 100644
--- a/src/QueryExecutionError.php
+++ b/src/PostgresQueryError.php
@@ -2,9 +2,9 @@
namespace Amp\Postgres;
-use Amp\Sql\QueryError;
+use Amp\Sql\SqlQueryError;
-class QueryExecutionError extends QueryError
+class PostgresQueryError extends SqlQueryError
{
/**
* @param array $diagnostics
diff --git a/src/PostgresResult.php b/src/PostgresResult.php
index 408cee1..19afe8a 100644
--- a/src/PostgresResult.php
+++ b/src/PostgresResult.php
@@ -2,15 +2,15 @@
namespace Amp\Postgres;
-use Amp\Sql\Result;
+use Amp\Sql\SqlResult;
/**
* Recursive template types currently not supported, list should be list.
* @psalm-type TFieldType = list|scalar|null
* @psalm-type TRowType = array
- * @extends Result
+ * @extends SqlResult
*/
-interface PostgresResult extends Result
+interface PostgresResult extends SqlResult
{
/**
* Changes return type to this library's Result type.
diff --git a/src/PostgresStatement.php b/src/PostgresStatement.php
index 7417498..c563da8 100644
--- a/src/PostgresStatement.php
+++ b/src/PostgresStatement.php
@@ -2,11 +2,11 @@
namespace Amp\Postgres;
-use Amp\Sql\Statement;
+use Amp\Sql\SqlStatement;
/**
- * @extends Statement
+ * @extends SqlStatement
*/
-interface PostgresStatement extends Statement
+interface PostgresStatement extends SqlStatement
{
}
diff --git a/src/PostgresTransaction.php b/src/PostgresTransaction.php
index 55904be..238387b 100644
--- a/src/PostgresTransaction.php
+++ b/src/PostgresTransaction.php
@@ -2,13 +2,13 @@
namespace Amp\Postgres;
-use Amp\Sql\Transaction;
+use Amp\Sql\SqlTransaction;
/**
* Note that notifications sent during a transaction are not delivered until the transaction has been committed.
*
- * @extends Transaction
+ * @extends SqlTransaction
*/
-interface PostgresTransaction extends PostgresLink, Transaction
+interface PostgresTransaction extends PostgresLink, SqlTransaction
{
}
diff --git a/src/PqConnection.php b/src/PqConnection.php
index 3284474..a9fd1e9 100644
--- a/src/PqConnection.php
+++ b/src/PqConnection.php
@@ -4,7 +4,7 @@
use Amp\Cancellation;
use Amp\DeferredFuture;
-use Amp\Sql\ConnectionException;
+use Amp\Sql\SqlConnectionException;
use pq;
use Revolt\EventLoop;
@@ -17,7 +17,7 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati
try {
$connection = new pq\Connection($config->getConnectionString(), pq\Connection::ASYNC);
} catch (pq\Exception $exception) {
- throw new ConnectionException("Could not connect to PostgreSQL server", 0, $exception);
+ throw new SqlConnectionException("Could not connect to PostgreSQL server", 0, $exception);
}
$connection->nonblocking = true;
@@ -33,7 +33,7 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati
return; // Connection still reading or writing, so return and leave callback enabled.
case pq\Connection::POLLING_FAILED:
- $deferred->error(new ConnectionException($connection->errorMessage));
+ $deferred->error(new SqlConnectionException($connection->errorMessage));
break;
case pq\Connection::POLLING_OK:
@@ -41,7 +41,7 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati
break;
default:
- $deferred->error(new ConnectionException('Unexpected connection status value: ' . $result));
+ $deferred->error(new SqlConnectionException('Unexpected connection status value: ' . $result));
break;
}
diff --git a/test/AbstractConnectionTest.php b/test/AbstractConnectionTest.php
index e061de6..b321835 100644
--- a/test/AbstractConnectionTest.php
+++ b/test/AbstractConnectionTest.php
@@ -5,10 +5,10 @@
use Amp\Future;
use Amp\Postgres\PostgresListener;
use Amp\Postgres\PostgresNotification;
-use Amp\Postgres\QueryExecutionError;
-use Amp\Sql\ConnectionException;
-use Amp\Sql\QueryError;
+use Amp\Postgres\PostgresQueryError;
+use Amp\Sql\SqlConnectionException;
use Amp\Sql\SqlException;
+use Amp\Sql\SqlQueryError;
use Revolt\EventLoop;
use function Amp\async;
use function Amp\delay;
@@ -31,7 +31,7 @@ public function testConnectionCloseDuringQuery(): void
try {
$query->await();
- self::fail(\sprintf('Expected %s to be thrown', ConnectionException::class));
+ self::fail(\sprintf('Expected %s to be thrown', SqlConnectionException::class));
} catch (SqlException) {
// Expected
}
@@ -92,7 +92,7 @@ public function testNotify()
*/
public function testListenOnSameChannel()
{
- $this->expectException(QueryError::class);
+ $this->expectException(SqlQueryError::class);
$this->expectExceptionMessage('Already listening on channel');
$channel = "test";
@@ -103,7 +103,7 @@ public function testQueryAfterErroredQuery()
{
try {
$result = $this->executor->query("INSERT INTO test VALUES ('github', 'com', '{1, 2, 3}', true, 4.2)");
- } catch (QueryExecutionError $exception) {
+ } catch (PostgresQueryError $exception) {
// Expected exception due to duplicate key.
}
diff --git a/test/AbstractLinkTest.php b/test/AbstractLinkTest.php
index ed47b07..6415b18 100644
--- a/test/AbstractLinkTest.php
+++ b/test/AbstractLinkTest.php
@@ -4,16 +4,16 @@
use Amp\Future;
use Amp\PHPUnit\AsyncTestCase;
-use Amp\Postgres\ByteA;
use Amp\Postgres\Internal\PostgresHandleConnection;
+use Amp\Postgres\PostgresByteA;
use Amp\Postgres\PostgresExecutor;
use Amp\Postgres\PostgresLink;
+use Amp\Postgres\PostgresQueryError;
use Amp\Postgres\PostgresTransaction;
-use Amp\Postgres\QueryExecutionError;
-use Amp\Sql\QueryError;
-use Amp\Sql\Result;
-use Amp\Sql\Statement;
-use Amp\Sql\TransactionError;
+use Amp\Sql\SqlQueryError;
+use Amp\Sql\SqlResult;
+use Amp\Sql\SqlStatement;
+use Amp\Sql\SqlTransactionError;
use function Amp\async;
abstract class AbstractLinkTest extends AsyncTestCase
@@ -38,9 +38,9 @@ abstract class AbstractLinkTest extends AsyncTestCase
protected function getParams(): array
{
return $this->data ??= [
- ['amphp', 'org', [1], true, 3.14159, null, new ByteA(\random_bytes(10)), \json_encode('string')],
- ['github', 'com', [1, 2, 3, 4, 5], false, 2.71828, null, new ByteA(\str_repeat("\0", 10)), \json_encode([1, 2, 3])],
- ['google', 'com', [1, 2, 3, 4], true, 1.61803, null, new ByteA(\random_bytes(42)), \json_encode(null)],
+ ['amphp', 'org', [1], true, 3.14159, null, new PostgresByteA(\random_bytes(10)), \json_encode('string')],
+ ['github', 'com', [1, 2, 3, 4, 5], false, 2.71828, null, new PostgresByteA(\str_repeat("\0", 10)), \json_encode([1, 2, 3])],
+ ['google', 'com', [1, 2, 3, 4], true, 1.61803, null, new PostgresByteA(\random_bytes(42)), \json_encode(null)],
['php', 'net', [1, 2], false, 0.0, null, null, \json_encode((object) ['value' => 1])],
];
}
@@ -51,12 +51,12 @@ protected function getParams(): array
protected function getData(): array
{
return \array_map(fn (array $params) => \array_map(
- fn (mixed $param) => $param instanceof ByteA ? $param->getData() : $param,
+ fn (mixed $param) => $param instanceof PostgresByteA ? $param->getData() : $param,
$params,
), $this->getParams());
}
- protected function verifyResult(Result $result, array $data): void
+ protected function verifyResult(SqlResult $result, array $data): void
{
$this->assertSame(self::FIELD_COUNT, $result->getColumnCount());
@@ -141,7 +141,7 @@ public function testMultipleQueryWithTupleResult()
$result = $result->getNextResult();
- $this->assertInstanceOf(Result::class, $result);
+ $this->assertInstanceOf(SqlResult::class, $result);
$this->verifyResult($result, $data);
@@ -156,7 +156,7 @@ public function testMultipleQueryWithCommandResultFirst()
$result = $result->getNextResult();
- $this->assertInstanceOf(Result::class, $result);
+ $this->assertInstanceOf(SqlResult::class, $result);
$data = $this->getData();
$data[] = ['canon', 'jp', [1], true, 4.2, null, null, \json_encode(3.1415926)]; // Add inserted row to expected data.
@@ -185,13 +185,13 @@ public function testQueryWithUnconsumedTupleResult()
{
$result = $this->executor->query("SELECT * FROM test");
- $this->assertInstanceOf(Result::class, $result);
+ $this->assertInstanceOf(SqlResult::class, $result);
unset($result); // Force destruction of result object.
$result = $this->executor->query("SELECT * FROM test");
- $this->assertInstanceOf(Result::class, $result);
+ $this->assertInstanceOf(SqlResult::class, $result);
$data = $this->getData();
@@ -207,17 +207,17 @@ public function testQueryWithCommandResult(): void
public function testQueryWithEmptyQuery(): void
{
- $this->expectException(QueryError::class);
+ $this->expectException(SqlQueryError::class);
$this->executor->query('');
}
public function testQueryWithSyntaxError()
{
- /** @var Result $result */
+ /** @var SqlResult $result */
try {
$result = $this->executor->query("SELECT & FROM test");
- $this->fail(\sprintf("An instance of %s was expected to be thrown", QueryExecutionError::class));
- } catch (QueryExecutionError $exception) {
+ $this->fail(\sprintf("An instance of %s was expected to be thrown", PostgresQueryError::class));
+ } catch (PostgresQueryError $exception) {
$diagnostics = $exception->getDiagnostics();
$this->assertArrayHasKey("sqlstate", $diagnostics);
}
@@ -323,7 +323,7 @@ public function testPrepareWithNamedParamsWithDataAppearingAsNamedParam()
*/
public function testPrepareInvalidQuery()
{
- $this->expectException(QueryExecutionError::class);
+ $this->expectException(PostgresQueryError::class);
$this->expectExceptionMessage('column "invalid" does not exist');
$query = "SELECT * FROM test WHERE invalid=\$1";
@@ -344,8 +344,8 @@ public function testPrepareSameQuery()
$statement2 = $this->executor->prepare($sql);
- $this->assertInstanceOf(Statement::class, $statement1);
- $this->assertInstanceOf(Statement::class, $statement2);
+ $this->assertInstanceOf(SqlStatement::class, $statement1);
+ $this->assertInstanceOf(SqlStatement::class, $statement2);
unset($statement1);
@@ -389,8 +389,8 @@ public function testPrepareSimilarQueryReturnsDifferentStatements()
[$statement1, $statement2] = Future\await([$statement1, $statement2]);
- $this->assertInstanceOf(Statement::class, $statement1);
- $this->assertInstanceOf(Statement::class, $statement2);
+ $this->assertInstanceOf(SqlStatement::class, $statement1);
+ $this->assertInstanceOf(SqlStatement::class, $statement2);
$this->assertNotSame($statement1, $statement2);
@@ -402,7 +402,7 @@ public function testPrepareSimilarQueryReturnsDifferentStatements()
$results[] = \iterator_to_array($statement2->execute(['domain' => $data[0]]));
foreach ($results as $result) {
- /** @var Result $result */
+ /** @var SqlResult $result */
foreach ($result as $row) {
$this->assertSame($data[0], $row['domain']);
$this->assertSame($data[1], $row['tld']);
@@ -492,7 +492,7 @@ public function testSimultaneousQuery()
*/
public function testSimultaneousQueryWithOneFailing()
{
- $callback = fn (string $query) => async(function () use ($query): Result {
+ $callback = fn (string $query) => async(function () use ($query): SqlResult {
$result = $this->executor->query($query);
$data = $this->getData();
@@ -515,12 +515,12 @@ public function testSimultaneousQueryWithOneFailing()
$result = $successful->await();
$failing->await();
- } catch (QueryError $exception) {
- $this->assertInstanceOf(Result::class, $result);
+ } catch (SqlQueryError $exception) {
+ $this->assertInstanceOf(SqlResult::class, $result);
return;
}
- $this->fail(\sprintf("Test did not throw an instance of %s", QueryError::class));
+ $this->fail(\sprintf("Test did not throw an instance of %s", SqlQueryError::class));
}
public function testSimultaneousQueryAndPrepare()
@@ -592,7 +592,7 @@ public function testTransaction()
try {
$result = $transaction->execute("SELECT * FROM test");
$this->fail('Query should fail after transaction commit');
- } catch (TransactionError $exception) {
+ } catch (SqlTransactionError $exception) {
// Exception expected.
}
}
@@ -612,7 +612,7 @@ public function provideInsertParameters(): iterable
'keys' => [1, 2, 3],
'enabled' => false,
'number' => 2.718,
- 'bytea' => new ByteA($data),
+ 'bytea' => new PostgresByteA($data),
],
['bytea' => $data],
];
diff --git a/test/ArrayParserTest.php b/test/ArrayParserTest.php
index 2a6447e..e147b1b 100644
--- a/test/ArrayParserTest.php
+++ b/test/ArrayParserTest.php
@@ -3,7 +3,7 @@
namespace Amp\Postgres\Test;
use Amp\Postgres\Internal\ArrayParser;
-use Amp\Postgres\ParseException;
+use Amp\Postgres\PostgresParseException;
use PHPUnit\Framework\TestCase;
class ArrayParserTest extends TestCase
@@ -135,7 +135,7 @@ public function testArrayWithEmptyString(): void
public function testMalformedNestedArray(): void
{
- $this->expectException(ParseException::class);
+ $this->expectException(PostgresParseException::class);
$this->expectExceptionMessage('Unexpected end of data');
$string = '{{}';
@@ -144,7 +144,7 @@ public function testMalformedNestedArray(): void
public function testEmptyString(): void
{
- $this->expectException(ParseException::class);
+ $this->expectException(PostgresParseException::class);
$this->expectExceptionMessage('Unexpected end of data');
$string = ' ';
@@ -153,7 +153,7 @@ public function testEmptyString(): void
public function testNoOpeningBracket(): void
{
- $this->expectException(ParseException::class);
+ $this->expectException(PostgresParseException::class);
$this->expectExceptionMessage('Missing opening bracket');
$string = '"one", "two"}';
@@ -162,7 +162,7 @@ public function testNoOpeningBracket(): void
public function testNoClosingBracket(): void
{
- $this->expectException(ParseException::class);
+ $this->expectException(PostgresParseException::class);
$this->expectExceptionMessage('Unexpected end of data');
$string = '{"one", "two"';
@@ -171,7 +171,7 @@ public function testNoClosingBracket(): void
public function testExtraClosingBracket(): void
{
- $this->expectException(ParseException::class);
+ $this->expectException(PostgresParseException::class);
$this->expectExceptionMessage('Data left in buffer after parsing');
$string = '{"one", "two"}}';
@@ -180,7 +180,7 @@ public function testExtraClosingBracket(): void
public function testTrailingData(): void
{
- $this->expectException(ParseException::class);
+ $this->expectException(PostgresParseException::class);
$this->expectExceptionMessage('Data left in buffer after parsing');
$string = '{"one", "two"} data}';
@@ -189,7 +189,7 @@ public function testTrailingData(): void
public function testMissingQuote(): void
{
- $this->expectException(ParseException::class);
+ $this->expectException(PostgresParseException::class);
$this->expectExceptionMessage('Could not find matching quote in quoted value');
$string = '{"one", "two}';
@@ -198,7 +198,7 @@ public function testMissingQuote(): void
public function testInvalidDelimiter(): void
{
- $this->expectException(ParseException::class);
+ $this->expectException(PostgresParseException::class);
$this->expectExceptionMessage('Invalid delimiter');
$string = '{"one"; "two"}';
diff --git a/test/PgSqlConnectionTest.php b/test/PgSqlConnectionTest.php
index b33f297..040ff2e 100644
--- a/test/PgSqlConnectionTest.php
+++ b/test/PgSqlConnectionTest.php
@@ -2,8 +2,8 @@
namespace Amp\Postgres\Test;
-use Amp\Postgres\ByteA;
use Amp\Postgres\PgSqlConnection;
+use Amp\Postgres\PostgresByteA;
use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresLink;
use Revolt\EventLoop;
@@ -51,7 +51,7 @@ public function createLink(string $connectionString): PostgresLink
private function cast(mixed $param): mixed
{
- return $param instanceof ByteA ? \pg_escape_bytea($this->handle, $param->getData()) : cast($param);
+ return $param instanceof PostgresByteA ? \pg_escape_bytea($this->handle, $param->getData()) : cast($param);
}
public function tearDown(): void
diff --git a/test/PgSqlPoolTest.php b/test/PgSqlPoolTest.php
index 304c9a1..530a7ac 100644
--- a/test/PgSqlPoolTest.php
+++ b/test/PgSqlPoolTest.php
@@ -2,12 +2,12 @@
namespace Amp\Postgres\Test;
-use Amp\Postgres\ByteA;
use Amp\Postgres\PgSqlConnection;
+use Amp\Postgres\PostgresByteA;
use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresConnectionPool;
use Amp\Postgres\PostgresLink;
-use Amp\Sql\Common\ConnectionPool;
+use Amp\Sql\Common\SqlCommonConnectionPool;
use Amp\Sql\SqlConnector;
use Revolt\EventLoop;
use function Amp\Postgres\Internal\cast;
@@ -52,7 +52,7 @@ public function createLink(string $connectionString): PostgresLink
);
});
- $pool = new PostgresConnectionPool(new PostgresConfig('localhost'), \count($this->handles), ConnectionPool::DEFAULT_IDLE_TIMEOUT, true, $connector);
+ $pool = new PostgresConnectionPool(new PostgresConfig('localhost'), \count($this->handles), SqlCommonConnectionPool::DEFAULT_IDLE_TIMEOUT, true, $connector);
$handle = \reset($this->handles);
@@ -77,7 +77,7 @@ public function createLink(string $connectionString): PostgresLink
private function cast(\PgSql\Connection $handle, mixed $param): mixed
{
- return $param instanceof ByteA ? \pg_escape_bytea($handle, $param->getData()) : cast($param);
+ return $param instanceof PostgresByteA ? \pg_escape_bytea($handle, $param->getData()) : cast($param);
}
public function tearDown(): void
diff --git a/test/PqConnectionTest.php b/test/PqConnectionTest.php
index dc2248e..9177430 100644
--- a/test/PqConnectionTest.php
+++ b/test/PqConnectionTest.php
@@ -2,9 +2,9 @@
namespace Amp\Postgres\Test;
-use Amp\Postgres\ByteA;
use Amp\Postgres\Internal\PqBufferedResultSet;
use Amp\Postgres\Internal\PqUnbufferedResultSet;
+use Amp\Postgres\PostgresByteA;
use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresLink;
use Amp\Postgres\PqConnection;
@@ -45,7 +45,7 @@ public function createLink(string $connectionString): PostgresLink
private function cast(mixed $param): mixed
{
- return $param instanceof ByteA ? $this->handle->escapeBytea($param->getData()) : cast($param);
+ return $param instanceof PostgresByteA ? $this->handle->escapeBytea($param->getData()) : cast($param);
}
public function tearDown(): void
diff --git a/test/PqPoolTest.php b/test/PqPoolTest.php
index c2e88d0..e7f27a0 100644
--- a/test/PqPoolTest.php
+++ b/test/PqPoolTest.php
@@ -2,12 +2,12 @@
namespace Amp\Postgres\Test;
-use Amp\Postgres\ByteA;
+use Amp\Postgres\PostgresByteA;
use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresConnectionPool;
use Amp\Postgres\PostgresLink;
use Amp\Postgres\PqConnection;
-use Amp\Sql\Common\ConnectionPool;
+use Amp\Sql\Common\SqlCommonConnectionPool;
use Amp\Sql\SqlConnector;
use function Amp\Postgres\Internal\cast;
@@ -43,7 +43,7 @@ public function createLink(string $connectionString): PostgresLink
return $this->newConnection(PqConnection::class, $handle, $config);
});
- $pool = new PostgresConnectionPool(new PostgresConfig('localhost'), \count($this->handles), ConnectionPool::DEFAULT_IDLE_TIMEOUT, true, $connector);
+ $pool = new PostgresConnectionPool(new PostgresConfig('localhost'), \count($this->handles), SqlCommonConnectionPool::DEFAULT_IDLE_TIMEOUT, true, $connector);
$handle = \reset($this->handles);
@@ -68,7 +68,7 @@ public function createLink(string $connectionString): PostgresLink
private function cast(\pq\Connection $connection, mixed $param): mixed
{
- return $param instanceof ByteA ? $connection->escapeBytea($param->getData()) : cast($param);
+ return $param instanceof PostgresByteA ? $connection->escapeBytea($param->getData()) : cast($param);
}
public function tearDown(): void