Skip to content

Commit

Permalink
Update for Sql prefixes in common libs
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Mar 1, 2024
1 parent c0144fe commit 801509d
Show file tree
Hide file tree
Showing 25 changed files with 109 additions and 110 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"amphp/parser": "^1.1",
"amphp/pipeline": "^1",
"amphp/socket": "^2",
"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-mysqli": "*",
Expand Down
38 changes: 19 additions & 19 deletions src/Internal/ConnectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
use Amp\Mysql\MysqlResult;
use Amp\Parser\Parser;
use Amp\Socket\Socket;
use Amp\Sql\ConnectionException;
use Amp\Sql\QueryError;
use Amp\Sql\SqlConnectionException;
use Amp\Sql\SqlQueryError;
use Amp\Sql\SqlException;
use Amp\Sql\TransientResource;
use Amp\Sql\SqlTransientResource;
use Revolt\EventLoop;

/* @TODO
Expand All @@ -31,7 +31,7 @@
* @internal
* @see https://dev.mysql.com/doc/dev/mysql-server/latest/PAGE_PROTOCOL.html Protocol documentation.
*/
class ConnectionProcessor implements TransientResource
class ConnectionProcessor implements SqlTransientResource
{
use ForbidCloning;
use ForbidSerialization;
Expand Down Expand Up @@ -238,7 +238,7 @@ public function connect(?Cancellation $cancellation = null): void
});
}

if ($this->config->getSqlMode()) {
if ($this->config->getSqlMode() !== null) {
$future = $future->map(function (): void {
$sqlMode = $this->config->getSqlMode();
$this->query("SET SESSION sql_mode='$sqlMode'")->await();
Expand Down Expand Up @@ -675,7 +675,7 @@ private function handleError(string $packet): void

if ($connecting) {
// connection failure
$this->free(new ConnectionException(\sprintf(
$this->free(new SqlConnectionException(\sprintf(
'Could not connect to %s: %s',
$this->config->getConnectionString(),
$this->metadata->errorMsg,
Expand All @@ -685,14 +685,14 @@ private function handleError(string $packet): void

if ($this->result === null && $this->deferreds->isEmpty()) {
// connection killed without pending query or active result
$this->free(new ConnectionException('Connection closed after receiving an unexpected error packet'));
$this->free(new SqlConnectionException('Connection closed after receiving an unexpected error packet'));
return;
}

$deferred = $this->result ?? $this->dequeueDeferred();

// normal error
$exception = new QueryError(\sprintf(
$exception = new SqlQueryError(\sprintf(
'MySQL error (%d): %s %s',
$this->metadata->errorCode,
$this->metadata->errorState ?? 'Unknown state',
Expand Down Expand Up @@ -809,7 +809,7 @@ private function handleHandshake(string $packet): void
}

if ($protocol !== 0x0a) {
throw new ConnectionException("Unsupported protocol version ".\ord($packet)." (Expected: 10)");
throw new SqlConnectionException("Unsupported protocol version ".\ord($packet)." (Expected: 10)");
}

$this->metadata->serverVersion = MysqlDataType::decodeNullTerminatedString($packet, $offset);
Expand Down Expand Up @@ -880,7 +880,7 @@ private function handleLocalInfileRequest(string $packet): void
}
$this->write("");
} catch (\Throwable $e) {
$this->dequeueDeferred()->error(new ConnectionException("Failed to transfer a file to the server", 0, $e));
$this->dequeueDeferred()->error(new SqlConnectionException("Failed to transfer a file to the server", 0, $e));
}
});
}
Expand Down Expand Up @@ -913,7 +913,7 @@ private function handleQuery(string $packet): void
if ($this->config->isLocalInfileEnabled()) {
$this->handleLocalInfileRequest($packet);
} else {
$this->dequeueDeferred()->error(new ConnectionException("Unexpected LOCAL_INFILE_REQUEST packet"));
$this->dequeueDeferred()->error(new SqlConnectionException("Unexpected LOCAL_INFILE_REQUEST packet"));
}
return;
case self::ERR_PACKET:
Expand Down Expand Up @@ -1173,7 +1173,7 @@ private function handlePrepare(string $packet): void
$this->handleError($packet);
return;
default:
throw new ConnectionException("Unexpected value for first byte of COM_STMT_PREPARE Response");
throw new SqlConnectionException("Unexpected value for first byte of COM_STMT_PREPARE Response");
}

$offset = 1;
Expand Down Expand Up @@ -1232,8 +1232,8 @@ private function free(?\Throwable $exception = null): void
$this->parser->cancel();

if (!$this->deferreds->isEmpty() || $this->result) {
if (!$exception instanceof ConnectionException) {
$exception = new ConnectionException("Connection closed unexpectedly", 0, $exception ?? null);
if (!$exception instanceof SqlConnectionException) {
$exception = new SqlConnectionException("Connection closed unexpectedly", 0, $exception ?? null);
}

while (!$this->deferreds->isEmpty()) {
Expand Down Expand Up @@ -1433,7 +1433,7 @@ private function parsePayload(string $packet): void
}
break;
default:
throw new ConnectionException(
throw new SqlConnectionException(
"Unexpected EXTRA_AUTH_PACKET in authentication phase for method {$this->authPluginName}"
);
}
Expand Down Expand Up @@ -1464,7 +1464,7 @@ private function parsePayload(string $packet): void
// no break
default:
if (!$cb) {
throw new ConnectionException("Unexpected packet type: " . \ord($packet));
throw new SqlConnectionException("Unexpected packet type: " . \ord($packet));
}

$cb($packet);
Expand Down Expand Up @@ -1514,7 +1514,7 @@ private function authSwitchRequest(string $packet): void
$this->handleError($packet);
return;
default:
throw new ConnectionException("AuthSwitchRequest: Expecting 0xfe (or ERR_Packet), got 0x".\dechex(\ord($packet)));
throw new SqlConnectionException("AuthSwitchRequest: Expecting 0xfe (or ERR_Packet), got 0x".\dechex(\ord($packet)));
}
}

Expand Down Expand Up @@ -1613,11 +1613,11 @@ private function getAuthData(): string
case "caching_sha2_password":
return self::sha2Auth($password, $this->authPluginData);
case "mysql_old_password":
throw new ConnectionException(
throw new SqlConnectionException(
"mysql_old_password is outdated and insecure. Intentionally not implemented!"
);
default:
throw new ConnectionException(
throw new SqlConnectionException(
"Invalid (or unimplemented?) auth method requested by server: {$this->authPluginName}"
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Internal/MysqlCommandResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Amp\Future;
use Amp\Mysql\MysqlResult;
use Amp\Sql\Common\CommandResult;
use Amp\Sql\Common\SqlCommandResult;

/**
* @internal
* @psalm-import-type TFieldType from MysqlResult
* @extends CommandResult<TFieldType, MysqlResult>
* @extends SqlCommandResult<TFieldType, MysqlResult>
*/
final class MysqlCommandResult extends CommandResult implements MysqlResult
final class MysqlCommandResult extends SqlCommandResult implements MysqlResult
{
private ?int $lastInsertId;

Expand Down
4 changes: 2 additions & 2 deletions src/Internal/MysqlConnectionStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Amp\ForbidSerialization;
use Amp\Mysql\MysqlResult;
use Amp\Mysql\MysqlStatement;
use Amp\Sql\ConnectionException;
use Amp\Sql\SqlConnectionException;
use Revolt\EventLoop;

/** @internal */
Expand Down Expand Up @@ -62,7 +62,7 @@ private function getProcessor(): ConnectionProcessor
}

if ($this->processor->isClosed()) {
throw new ConnectionException("Connection went away");
throw new SqlConnectionException("Connection went away");
}

return $this->processor;
Expand Down
14 changes: 7 additions & 7 deletions src/Internal/MysqlConnectionTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
use Amp\Mysql\MysqlResult;
use Amp\Mysql\MysqlStatement;
use Amp\Mysql\MysqlTransaction;
use Amp\Sql\Common\ConnectionTransaction;
use Amp\Sql\Common\NestableTransactionExecutor;
use Amp\Sql\Transaction;
use Amp\Sql\Common\SqlConnectionTransaction;
use Amp\Sql\Common\SqlNestableTransactionExecutor;
use Amp\Sql\SqlTransaction;

/**
* @internal
* @extends ConnectionTransaction<MysqlResult, MysqlStatement, MysqlTransaction, MysqlNestableExecutor>
* @extends SqlConnectionTransaction<MysqlResult, MysqlStatement, MysqlTransaction, MysqlNestableExecutor>
*/
final class MysqlConnectionTransaction extends ConnectionTransaction implements MysqlTransaction
final class MysqlConnectionTransaction extends SqlConnectionTransaction implements MysqlTransaction
{
use MysqlTransactionDelegate;

protected function createNestedTransaction(
Transaction $transaction,
NestableTransactionExecutor $executor,
SqlTransaction $transaction,
SqlNestableTransactionExecutor $executor,
string $identifier,
\Closure $release,
): MysqlTransaction {
Expand Down
6 changes: 3 additions & 3 deletions src/Internal/MysqlNestableExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Amp\Mysql\MysqlExecutor;
use Amp\Mysql\MysqlResult;
use Amp\Mysql\MysqlStatement;
use Amp\Sql\Common\NestableTransactionExecutor;
use Amp\Sql\Common\SqlNestableTransactionExecutor;

/**
* @internal
* @implements NestableTransactionExecutor<MysqlResult, MysqlStatement>
* @implements SqlNestableTransactionExecutor<MysqlResult, MysqlStatement>
*/
final class MysqlNestableExecutor implements MysqlExecutor, NestableTransactionExecutor
final class MysqlNestableExecutor implements MysqlExecutor, SqlNestableTransactionExecutor
{
use ForbidCloning;
use ForbidSerialization;
Expand Down
14 changes: 7 additions & 7 deletions src/Internal/MysqlNestedTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
use Amp\Mysql\MysqlResult;
use Amp\Mysql\MysqlStatement;
use Amp\Mysql\MysqlTransaction;
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<MysqlResult, MysqlStatement, MysqlTransaction, MysqlNestableExecutor>
* @extends SqlNestedTransaction<MysqlResult, MysqlStatement, MysqlTransaction, MysqlNestableExecutor>
*/
final class MysqlNestedTransaction extends NestedTransaction implements MysqlTransaction
final class MysqlNestedTransaction extends SqlNestedTransaction implements MysqlTransaction
{
use MysqlTransactionDelegate;

Expand All @@ -36,8 +36,8 @@ protected function getTransaction(): MysqlTransaction
}

protected function createNestedTransaction(
Transaction $transaction,
NestableTransactionExecutor $executor,
SqlTransaction $transaction,
SqlNestableTransactionExecutor $executor,
string $identifier,
\Closure $release,
): MysqlTransaction {
Expand Down
10 changes: 5 additions & 5 deletions src/Internal/MysqlPooledResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
namespace Amp\Mysql\Internal;

use Amp\Mysql\MysqlResult;
use Amp\Sql\Common\PooledResult;
use Amp\Sql\Result;
use Amp\Sql\Common\SqlPooledResult;
use Amp\Sql\SqlResult;

/**
* @internal
* @psalm-import-type TFieldType from MysqlResult
* @extends PooledResult<TFieldType, MysqlResult>
* @extends SqlPooledResult<TFieldType, MysqlResult>
*/
final class MysqlPooledResult extends PooledResult implements MysqlResult
final class MysqlPooledResult extends SqlPooledResult implements MysqlResult
{
private readonly MysqlResult $result;

Expand All @@ -24,7 +24,7 @@ public function __construct(MysqlResult $result, \Closure $release)
$this->result = $result;
}

protected static function newInstanceFrom(Result $result, \Closure $release): self
protected static function newInstanceFrom(SqlResult $result, \Closure $release): self
{
\assert($result instanceof MysqlResult);
return new self($result, $release);
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/MysqlPooledStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Amp\Mysql\MysqlResult;
use Amp\Mysql\MysqlStatement;
use Amp\Sql\Common\PooledStatement;
use Amp\Sql\Result as SqlResult;
use Amp\Sql\Common\SqlPooledStatement;
use Amp\Sql\SqlResult;

/**
* @internal
* @extends PooledStatement<MysqlResult, MysqlStatement>
* @extends SqlPooledStatement<MysqlResult, MysqlStatement>
*/
final class MysqlPooledStatement extends PooledStatement implements MysqlStatement
final class MysqlPooledStatement extends SqlPooledStatement implements MysqlStatement
{
/**
* @param \Closure():void $release
Expand Down
10 changes: 5 additions & 5 deletions src/Internal/MysqlPooledTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
use Amp\Mysql\MysqlResult;
use Amp\Mysql\MysqlStatement;
use Amp\Mysql\MysqlTransaction;
use Amp\Sql\Common\PooledTransaction;
use Amp\Sql\Transaction;
use Amp\Sql\Common\SqlPooledTransaction;
use Amp\Sql\SqlTransaction;

/**
* @internal
* @extends PooledTransaction<MysqlResult, MysqlStatement, MysqlTransaction>
* @extends SqlPooledTransaction<MysqlResult, MysqlStatement, MysqlTransaction>
*/
final class MysqlPooledTransaction extends PooledTransaction implements MysqlTransaction
final class MysqlPooledTransaction extends SqlPooledTransaction implements MysqlTransaction
{
use MysqlTransactionDelegate;

Expand All @@ -24,7 +24,7 @@ public function __construct(private readonly MysqlTransaction $transaction, \Clo
parent::__construct($transaction, $release);
}

protected function createTransaction(Transaction $transaction, \Closure $release): Transaction
protected function createTransaction(SqlTransaction $transaction, \Closure $release): MysqlTransaction
{
\assert($transaction instanceof MysqlTransaction);
return new MysqlPooledTransaction($transaction, $release);
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/MysqlStatementPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use Amp\Mysql\MysqlResult;
use Amp\Mysql\MysqlStatement;
use Amp\Mysql\MysqlTransaction;
use Amp\Sql\Common\StatementPool as SqlStatementPool;
use Amp\Sql\Result as SqlResult;
use Amp\Sql\Statement;
use Amp\Sql\Common\SqlStatementPool;
use Amp\Sql\SqlResult;
use Amp\Sql\SqlStatement;

/**
* @internal
Expand Down Expand Up @@ -36,7 +36,7 @@ protected function pop(): MysqlStatement
return $statement;
}

protected function push(Statement $statement): void
protected function push(SqlStatement $statement): void
{
if ($statement->isClosed()) {
return;
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/MysqlTransactionDelegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
use Amp\Mysql\MysqlResult;
use Amp\Mysql\MysqlStatement;
use Amp\Mysql\MysqlTransaction;
use Amp\Sql\Result;
use Amp\Sql\Statement;
use Amp\Sql\SqlResult;
use Amp\Sql\SqlStatement;

/** @internal */
trait MysqlTransactionDelegate
{
protected function createStatement(
Statement $statement,
SqlStatement $statement,
\Closure $release,
?\Closure $awaitBusyResource = null,
): MysqlStatement {
\assert($statement instanceof MysqlStatement);
return new MysqlPooledStatement($statement, $release, $awaitBusyResource);
}

protected function createResult(Result $result, \Closure $release): MysqlResult
protected function createResult(SqlResult $result, \Closure $release): MysqlResult
{
\assert($result instanceof MysqlResult);
return new MysqlPooledResult($result, $release);
Expand Down
Loading

0 comments on commit 801509d

Please sign in to comment.