Add template types to most interfaces

This commit is contained in:
Aaron Piotrowski 2022-07-08 16:55:14 -05:00
parent 3060e7f9f1
commit 4a1c63240e
No known key found for this signature in database
GPG Key ID: 5B456E6AABA44A63
6 changed files with 51 additions and 2 deletions

View File

@ -2,11 +2,17 @@
namespace Amp\Sql;
/**
* @template TResult extends Result
* @template TStatement extends Statement
*/
interface Executor extends TransientResource
{
/**
* @param string $sql SQL query to execute.
*
* @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).
@ -16,6 +22,8 @@ interface Executor extends TransientResource
/**
* @param string $sql SQL query to prepare.
*
* @return TStatement
*
* @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).
@ -26,9 +34,16 @@ interface Executor extends TransientResource
* @param string $sql SQL query to prepare and execute.
* @param mixed[] $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;
/**
* Closes the executor. No further queries may be performed.
*/
public function close(): void;
}

View File

@ -2,12 +2,21 @@
namespace Amp\Sql;
/**
* @template TResult extends Result
* @template TStatement extends Statement
* @template TTransaction extends Transaction
*
* @extends Executor<TResult, TStatement>
*/
interface Link extends Executor
{
/**
* Starts a transaction on a single connection.
*
* @param TransactionIsolation $isolation Transaction isolation level.
* @param TransactionIsolation $isolation Transaction isolation level.'
*
* @return TTransaction
*/
public function beginTransaction(
TransactionIsolation $isolation = TransactionIsolationLevel::Committed,

View File

@ -2,11 +2,20 @@
namespace Amp\Sql;
/**
* @template TResult extends Result
* @template TStatement extends Statement
* @template TTransaction extends Transaction
*
* @extends Link<TResult, TStatement, TTransaction>
*/
interface Pool extends Link
{
/**
* 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 Link<TResult, TStatement, TTransaction>
*/
public function extractConnection(): Link;

View File

@ -4,11 +4,19 @@ namespace Amp\Sql;
use Amp\Cancellation;
/**
* @template TConfig extends SqlConfig
* @template TLink extends Link
*/
interface SqlConnector
{
/**
* Returns a new database connection based on the given configuration.
* Implementations may provide further parameters, such as a Cancellation.
*
* @param TConfig $config
*
* @return TLink
*/
public function connect(SqlConfig $config, ?Cancellation $cancellation = null): Link;
}

View File

@ -2,10 +2,13 @@
namespace Amp\Sql;
/**
* @template TResult extends Result
*/
interface Statement extends TransientResource
{
/**
* @param mixed[] $params
* @return TResult
*/
public function execute(array $params = []): Result;

View File

@ -2,6 +2,11 @@
namespace Amp\Sql;
/**
* @template TResult extends Result
* @template TStatement extends Statement
* @extends Executor<TResult, TStatement>
*/
interface Transaction extends Executor
{
public function getIsolationLevel(): TransactionIsolation;