Skip to content

Commit

Permalink
Add Sql prefix to all classes
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Feb 25, 2024
1 parent 9479805 commit 566fea7
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 144 deletions.
31 changes: 0 additions & 31 deletions src/Connection.php

This file was deleted.

44 changes: 0 additions & 44 deletions src/Executor.php

This file was deleted.

20 changes: 0 additions & 20 deletions src/Link.php

This file was deleted.

31 changes: 31 additions & 0 deletions src/SqlConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

namespace Amp\Sql;

/**
* @template TConfig of SqlConfig
* @template TResult of SqlResult
* @template TStatement of SqlStatement<TResult>
* @template TTransaction of SqlTransaction
*
* @extends SqlLink<TResult, TStatement, TTransaction>
*/
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Amp\Sql;

class ConnectionException extends SqlException
class SqlConnectionException extends SqlException
{
}
14 changes: 7 additions & 7 deletions src/Pool.php → src/SqlConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

/**
* @template TConfig of SqlConfig
* @template TResult of Result
* @template TStatement of Statement<TResult>
* @template TTransaction of Transaction
* @template TResult of SqlResult
* @template TStatement of SqlStatement<TResult>
* @template TTransaction of SqlTransaction
*
* @extends Connection<TConfig, TResult, TStatement, TTransaction>
* @extends SqlConnection<TConfig, TResult, TStatement, TTransaction>
*/
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<TConfig, TResult, TStatement, TTransaction>
* @return SqlConnection<TConfig, TResult, TStatement, TTransaction>
*/
public function extractConnection(): Connection;
public function extractConnection(): SqlConnection;

/**
* @return int Total number of active connections in the pool.
Expand Down
6 changes: 3 additions & 3 deletions src/SqlConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* @template TConfig of SqlConfig
* @template TConnection of Connection
* @template TConnection of SqlConnection
*/
interface SqlConnector
{
Expand All @@ -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;
}
44 changes: 44 additions & 0 deletions src/SqlExecutor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

namespace Amp\Sql;

/**
* @template TResult of SqlResult
* @template TStatement of SqlStatement
*/
interface SqlExecutor extends SqlTransientResource
{
/**
* @param string $sql SQL query to execute.
*
* @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 query(string $sql): SqlResult;

/**
* @param string $sql SQL query to prepare.
*
* @return TStatement
*
* @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 prepare(string $sql): SqlStatement;

/**
* @param string $sql SQL query to prepare and execute.
* @param array<int, mixed>|array<string, mixed> $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;
}
20 changes: 20 additions & 0 deletions src/SqlLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace Amp\Sql;

/**
* @template TResult of SqlResult
* @template TStatement of SqlStatement<TResult>
* @template TTransaction of SqlTransaction
*
* @extends SqlExecutor<TResult, TStatement>
*/
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;
}
2 changes: 1 addition & 1 deletion src/QueryError.php → src/SqlQueryError.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amp\Sql;

class QueryError extends \Error
class SqlQueryError extends \Error
{
public function __construct(
string $message,
Expand Down
4 changes: 2 additions & 2 deletions src/Result.php → src/SqlResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @template TFieldValue
* @extends \Traversable<int, array<string, TFieldValue>>
*/
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
Expand All @@ -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<TFieldValue>|null
* @return SqlResult<TFieldValue>|null
*/
public function getNextResult(): ?self;

Expand Down
6 changes: 3 additions & 3 deletions src/Statement.php → src/SqlStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions src/Transaction.php → src/SqlTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
namespace Amp\Sql;

/**
* @template TResult of Result
* @template TStatement of Statement<TResult>
* @template TTransaction of Transaction
* @template TResult of SqlResult
* @template TStatement of SqlStatement<TResult>
* @template TTransaction of SqlTransaction
*
* @extends Link<TResult, TStatement, TTransaction>
* @extends SqlLink<TResult, TStatement, TTransaction>
*/
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.
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/TransactionError.php → src/SqlTransactionError.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

namespace Amp\Sql;

class TransactionError extends \Error
class SqlTransactionError extends \Error
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amp\Sql;

interface TransactionIsolation
interface SqlTransactionIsolation
{
/**
* @return string Human-readable label for the transaction isolation level.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Amp\Sql;

enum TransactionIsolationLevel implements TransactionIsolation
enum SqlTransactionIsolationLevel implements SqlTransactionIsolation
{
case Uncommitted;
case Committed;
Expand Down
2 changes: 1 addition & 1 deletion src/TransientResource.php → src/SqlTransientResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 0 additions & 20 deletions test/QueryErrorTest.php

This file was deleted.

0 comments on commit 566fea7

Please sign in to comment.