From 566fea767d0c743207022438d6ce6a7d145b7537 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sun, 25 Feb 2024 12:32:12 -0600 Subject: [PATCH] Add Sql prefix to all classes --- src/Connection.php | 31 ------------- src/Executor.php | 44 ------------------- src/Link.php | 20 --------- src/SqlConnection.php | 31 +++++++++++++ ...ception.php => SqlConnectionException.php} | 2 +- src/{Pool.php => SqlConnectionPool.php} | 14 +++--- src/SqlConnector.php | 6 +-- src/SqlExecutor.php | 44 +++++++++++++++++++ src/SqlLink.php | 20 +++++++++ src/{QueryError.php => SqlQueryError.php} | 2 +- src/{Result.php => SqlResult.php} | 4 +- src/{Statement.php => SqlStatement.php} | 6 +-- src/{Transaction.php => SqlTransaction.php} | 16 +++---- ...ctionError.php => SqlTransactionError.php} | 2 +- ...lation.php => SqlTransactionIsolation.php} | 2 +- ...l.php => SqlTransactionIsolationLevel.php} | 2 +- ...tResource.php => SqlTransientResource.php} | 2 +- test/QueryErrorTest.php | 20 --------- test/SqlQueryErrorTest.php | 20 +++++++++ 19 files changed, 144 insertions(+), 144 deletions(-) delete mode 100644 src/Connection.php delete mode 100644 src/Executor.php delete mode 100644 src/Link.php create mode 100644 src/SqlConnection.php rename src/{ConnectionException.php => SqlConnectionException.php} (52%) rename src/{Pool.php => SqlConnectionPool.php} (69%) create mode 100644 src/SqlExecutor.php create mode 100644 src/SqlLink.php rename src/{QueryError.php => SqlQueryError.php} (95%) rename src/{Result.php => SqlResult.php} (92%) rename src/{Statement.php => SqlStatement.php} (60%) rename src/{Transaction.php => SqlTransaction.php} (74%) rename src/{TransactionError.php => SqlTransactionError.php} (57%) rename src/{TransactionIsolation.php => SqlTransactionIsolation.php} (90%) rename src/{TransactionIsolationLevel.php => SqlTransactionIsolationLevel.php} (91%) rename src/{TransientResource.php => SqlTransientResource.php} (83%) delete mode 100644 test/QueryErrorTest.php create mode 100644 test/SqlQueryErrorTest.php diff --git a/src/Connection.php b/src/Connection.php deleted file mode 100644 index 4e1b6d8..0000000 --- a/src/Connection.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @template TTransaction of Transaction - * - * @extends Link - */ -interface Connection extends Link -{ - /** - * @return TConfig The configuration used to create this connection. - */ - public function getConfig(): SqlConfig; - - /** - * @return TransactionIsolation Current transaction isolation used when beginning transactions on this connection. - */ - public function getTransactionIsolation(): TransactionIsolation; - - /** - * Sets the transaction isolation level for transactions began on this link. - * - * @see Link::beginTransaction() - */ - public function setTransactionIsolation(TransactionIsolation $isolation): void; -} diff --git a/src/Executor.php b/src/Executor.php deleted file mode 100644 index 130e2a2..0000000 --- a/src/Executor.php +++ /dev/null @@ -1,44 +0,0 @@ -|array $params Query parameters. - * - * @return TResult - * - * @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). - */ - public function execute(string $sql, array $params = []): Result; -} diff --git a/src/Link.php b/src/Link.php deleted file mode 100644 index ca47bb2..0000000 --- a/src/Link.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @template TTransaction of Transaction - * - * @extends Executor - */ -interface Link extends Executor -{ - /** - * Starts a transaction, returning an object where all queries are executed on a single connection. - * - * @return TTransaction - */ - public function beginTransaction(): Transaction; -} diff --git a/src/SqlConnection.php b/src/SqlConnection.php new file mode 100644 index 0000000..fc0c38b --- /dev/null +++ b/src/SqlConnection.php @@ -0,0 +1,31 @@ + + * @template TTransaction of SqlTransaction + * + * @extends SqlLink + */ +interface SqlConnection extends SqlLink +{ + /** + * @return TConfig The configuration used to create this connection. + */ + public function getConfig(): SqlConfig; + + /** + * @return SqlTransactionIsolation Current transaction isolation used when beginning transactions on this connection. + */ + public function getTransactionIsolation(): SqlTransactionIsolation; + + /** + * Sets the transaction isolation level for transactions began on this link. + * + * @see SqlLink::beginTransaction() + */ + public function setTransactionIsolation(SqlTransactionIsolation $isolation): void; +} diff --git a/src/ConnectionException.php b/src/SqlConnectionException.php similarity index 52% rename from src/ConnectionException.php rename to src/SqlConnectionException.php index 8942115..15afb97 100644 --- a/src/ConnectionException.php +++ b/src/SqlConnectionException.php @@ -2,6 +2,6 @@ namespace Amp\Sql; -class ConnectionException extends SqlException +class SqlConnectionException extends SqlException { } diff --git a/src/Pool.php b/src/SqlConnectionPool.php similarity index 69% rename from src/Pool.php rename to src/SqlConnectionPool.php index 0135de2..7981be8 100644 --- a/src/Pool.php +++ b/src/SqlConnectionPool.php @@ -4,21 +4,21 @@ /** * @template TConfig of SqlConfig - * @template TResult of Result - * @template TStatement of Statement - * @template TTransaction of Transaction + * @template TResult of SqlResult + * @template TStatement of SqlStatement + * @template TTransaction of SqlTransaction * - * @extends Connection + * @extends SqlConnection */ -interface Pool extends Connection +interface SqlConnectionPool extends SqlConnection { /** * Gets a single connection from the pool to run a set of queries against a single connection. * Generally a transaction should be used instead of this method. * - * @return Connection + * @return SqlConnection */ - public function extractConnection(): Connection; + public function extractConnection(): SqlConnection; /** * @return int Total number of active connections in the pool. diff --git a/src/SqlConnector.php b/src/SqlConnector.php index 01cb696..4adbe3e 100644 --- a/src/SqlConnector.php +++ b/src/SqlConnector.php @@ -6,7 +6,7 @@ /** * @template TConfig of SqlConfig - * @template TConnection of Connection + * @template TConnection of SqlConnection */ interface SqlConnector { @@ -18,7 +18,7 @@ interface SqlConnector * * @return TConnection * - * @throws ConnectionException + * @throws SqlConnectionException */ - public function connect(SqlConfig $config, ?Cancellation $cancellation = null): Connection; + public function connect(SqlConfig $config, ?Cancellation $cancellation = null): SqlConnection; } diff --git a/src/SqlExecutor.php b/src/SqlExecutor.php new file mode 100644 index 0000000..b47c71e --- /dev/null +++ b/src/SqlExecutor.php @@ -0,0 +1,44 @@ +|array $params Query parameters. + * + * @return TResult + * + * @throws SqlException If the operation fails due to unexpected condition. + * @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 execute(string $sql, array $params = []): SqlResult; +} diff --git a/src/SqlLink.php b/src/SqlLink.php new file mode 100644 index 0000000..5f22c1b --- /dev/null +++ b/src/SqlLink.php @@ -0,0 +1,20 @@ + + * @template TTransaction of SqlTransaction + * + * @extends SqlExecutor + */ +interface SqlLink extends SqlExecutor +{ + /** + * Starts a transaction, returning an object where all queries are executed on a single connection. + * + * @return TTransaction + */ + public function beginTransaction(): SqlTransaction; +} diff --git a/src/QueryError.php b/src/SqlQueryError.php similarity index 95% rename from src/QueryError.php rename to src/SqlQueryError.php index 3c57d8f..0e49b7f 100644 --- a/src/QueryError.php +++ b/src/SqlQueryError.php @@ -2,7 +2,7 @@ namespace Amp\Sql; -class QueryError extends \Error +class SqlQueryError extends \Error { public function __construct( string $message, diff --git a/src/Result.php b/src/SqlResult.php similarity index 92% rename from src/Result.php rename to src/SqlResult.php index b3ee8f2..441f619 100644 --- a/src/Result.php +++ b/src/SqlResult.php @@ -6,7 +6,7 @@ * @template TFieldValue * @extends \Traversable> */ -interface Result extends \Traversable +interface SqlResult extends \Traversable { /** * Returns the next row in the result set or null if no rows remain. This method may be used as an alternative @@ -20,7 +20,7 @@ public function fetchRow(): ?array; * Resolves with a new instance of Result if another result is available after this result. Resolves with null if * no further results are available. * - * @return Result|null + * @return SqlResult|null */ public function getNextResult(): ?self; diff --git a/src/Statement.php b/src/SqlStatement.php similarity index 60% rename from src/Statement.php rename to src/SqlStatement.php index a4eecf1..1ddb7d5 100644 --- a/src/Statement.php +++ b/src/SqlStatement.php @@ -3,14 +3,14 @@ namespace Amp\Sql; /** - * @template TResult of Result + * @template TResult of SqlResult */ -interface Statement extends TransientResource +interface SqlStatement extends SqlTransientResource { /** * @return TResult */ - public function execute(array $params = []): Result; + public function execute(array $params = []): SqlResult; /** * @return string The SQL string used to prepare the statement. diff --git a/src/Transaction.php b/src/SqlTransaction.php similarity index 74% rename from src/Transaction.php rename to src/SqlTransaction.php index 294425a..99fef5a 100644 --- a/src/Transaction.php +++ b/src/SqlTransaction.php @@ -3,15 +3,15 @@ namespace Amp\Sql; /** - * @template TResult of Result - * @template TStatement of Statement - * @template TTransaction of Transaction + * @template TResult of SqlResult + * @template TStatement of SqlStatement + * @template TTransaction of SqlTransaction * - * @extends Link + * @extends SqlLink */ -interface Transaction extends Link +interface SqlTransaction extends SqlLink { - public function getIsolation(): TransactionIsolation; + public function getIsolation(): SqlTransactionIsolation; /** * @return bool True if the transaction is active, false if it has been committed or rolled back. @@ -26,14 +26,14 @@ public function getSavepointIdentifier(): ?string; /** * Commits the transaction and makes it inactive. * - * @throws TransactionError If the transaction has been committed or rolled back. + * @throws SqlTransactionError If the transaction has been committed or rolled back. */ public function commit(): void; /** * Rolls back the transaction and makes it inactive. * - * @throws TransactionError If the transaction has been committed or rolled back. + * @throws SqlTransactionError If the transaction has been committed or rolled back. */ public function rollback(): void; diff --git a/src/TransactionError.php b/src/SqlTransactionError.php similarity index 57% rename from src/TransactionError.php rename to src/SqlTransactionError.php index 388890f..ab1e050 100644 --- a/src/TransactionError.php +++ b/src/SqlTransactionError.php @@ -2,6 +2,6 @@ namespace Amp\Sql; -class TransactionError extends \Error +class SqlTransactionError extends \Error { } diff --git a/src/TransactionIsolation.php b/src/SqlTransactionIsolation.php similarity index 90% rename from src/TransactionIsolation.php rename to src/SqlTransactionIsolation.php index a595e12..5ea9958 100644 --- a/src/TransactionIsolation.php +++ b/src/SqlTransactionIsolation.php @@ -2,7 +2,7 @@ namespace Amp\Sql; -interface TransactionIsolation +interface SqlTransactionIsolation { /** * @return string Human-readable label for the transaction isolation level. diff --git a/src/TransactionIsolationLevel.php b/src/SqlTransactionIsolationLevel.php similarity index 91% rename from src/TransactionIsolationLevel.php rename to src/SqlTransactionIsolationLevel.php index 14541ff..a2b6c9a 100644 --- a/src/TransactionIsolationLevel.php +++ b/src/SqlTransactionIsolationLevel.php @@ -2,7 +2,7 @@ namespace Amp\Sql; -enum TransactionIsolationLevel implements TransactionIsolation +enum SqlTransactionIsolationLevel implements SqlTransactionIsolation { case Uncommitted; case Committed; diff --git a/src/TransientResource.php b/src/SqlTransientResource.php similarity index 83% rename from src/TransientResource.php rename to src/SqlTransientResource.php index 82906b2..4aa9789 100644 --- a/src/TransientResource.php +++ b/src/SqlTransientResource.php @@ -4,7 +4,7 @@ use Amp\Closable; -interface TransientResource extends Closable +interface SqlTransientResource extends Closable { /** * Get the timestamp of the last usage of this resource. diff --git a/test/QueryErrorTest.php b/test/QueryErrorTest.php deleted file mode 100644 index bcd61cf..0000000 --- a/test/QueryErrorTest.php +++ /dev/null @@ -1,20 +0,0 @@ -getQuery()); - self::assertStringStartsWith("Amp\Sql\QueryError: error\nCurrent query was SELECT * FROM foo", (string) $error); - } -} diff --git a/test/SqlQueryErrorTest.php b/test/SqlQueryErrorTest.php new file mode 100644 index 0000000..f674b9c --- /dev/null +++ b/test/SqlQueryErrorTest.php @@ -0,0 +1,20 @@ +getQuery()); + self::assertStringStartsWith("Amp\Sql\SqlQueryError: error\nCurrent query was SELECT * FROM foo", (string) $error); + } +}