mirror of
https://github.com/danog/sql.git
synced 2024-11-26 20:15:08 +01:00
Add template types to most interfaces
This commit is contained in:
parent
3060e7f9f1
commit
4a1c63240e
@ -2,11 +2,17 @@
|
|||||||
|
|
||||||
namespace Amp\Sql;
|
namespace Amp\Sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template TResult extends Result
|
||||||
|
* @template TStatement extends Statement
|
||||||
|
*/
|
||||||
interface Executor extends TransientResource
|
interface Executor extends TransientResource
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param string $sql SQL query to execute.
|
* @param string $sql SQL query to execute.
|
||||||
*
|
*
|
||||||
|
* @return TResult
|
||||||
|
*
|
||||||
* @throws SqlException If the operation fails due to unexpected condition.
|
* @throws SqlException If the operation fails due to unexpected condition.
|
||||||
* @throws ConnectionException If the connection to the database is lost.
|
* @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 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.
|
* @param string $sql SQL query to prepare.
|
||||||
*
|
*
|
||||||
|
* @return TStatement
|
||||||
|
*
|
||||||
* @throws SqlException If the operation fails due to unexpected condition.
|
* @throws SqlException If the operation fails due to unexpected condition.
|
||||||
* @throws ConnectionException If the connection to the database is lost.
|
* @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 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 string $sql SQL query to prepare and execute.
|
||||||
* @param mixed[] $params Query parameters.
|
* @param mixed[] $params Query parameters.
|
||||||
*
|
*
|
||||||
|
* @return TResult
|
||||||
|
*
|
||||||
* @throws SqlException If the operation fails due to unexpected condition.
|
* @throws SqlException If the operation fails due to unexpected condition.
|
||||||
* @throws ConnectionException If the connection to the database is lost.
|
* @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 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;
|
public function execute(string $sql, array $params = []): Result;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the executor. No further queries may be performed.
|
||||||
|
*/
|
||||||
|
public function close(): void;
|
||||||
}
|
}
|
||||||
|
11
src/Link.php
11
src/Link.php
@ -2,12 +2,21 @@
|
|||||||
|
|
||||||
namespace Amp\Sql;
|
namespace Amp\Sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template TResult extends Result
|
||||||
|
* @template TStatement extends Statement
|
||||||
|
* @template TTransaction extends Transaction
|
||||||
|
*
|
||||||
|
* @extends Executor<TResult, TStatement>
|
||||||
|
*/
|
||||||
interface Link extends Executor
|
interface Link extends Executor
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Starts a transaction on a single connection.
|
* Starts a transaction on a single connection.
|
||||||
*
|
*
|
||||||
* @param TransactionIsolation $isolation Transaction isolation level.
|
* @param TransactionIsolation $isolation Transaction isolation level.'
|
||||||
|
*
|
||||||
|
* @return TTransaction
|
||||||
*/
|
*/
|
||||||
public function beginTransaction(
|
public function beginTransaction(
|
||||||
TransactionIsolation $isolation = TransactionIsolationLevel::Committed,
|
TransactionIsolation $isolation = TransactionIsolationLevel::Committed,
|
||||||
|
@ -2,11 +2,20 @@
|
|||||||
|
|
||||||
namespace Amp\Sql;
|
namespace Amp\Sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template TResult extends Result
|
||||||
|
* @template TStatement extends Statement
|
||||||
|
* @template TTransaction extends Transaction
|
||||||
|
*
|
||||||
|
* @extends Link<TResult, TStatement, TTransaction>
|
||||||
|
*/
|
||||||
interface Pool extends Link
|
interface Pool extends Link
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Gets a single connection from the pool to run a set of queries against a single connection.
|
* 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.
|
* Generally a transaction should be used instead of this method.
|
||||||
|
*
|
||||||
|
* @return Link<TResult, TStatement, TTransaction>
|
||||||
*/
|
*/
|
||||||
public function extractConnection(): Link;
|
public function extractConnection(): Link;
|
||||||
|
|
||||||
|
@ -4,11 +4,19 @@ namespace Amp\Sql;
|
|||||||
|
|
||||||
use Amp\Cancellation;
|
use Amp\Cancellation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template TConfig extends SqlConfig
|
||||||
|
* @template TLink extends Link
|
||||||
|
*/
|
||||||
interface SqlConnector
|
interface SqlConnector
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns a new database connection based on the given configuration.
|
* Returns a new database connection based on the given configuration.
|
||||||
* Implementations may provide further parameters, such as a Cancellation.
|
* Implementations may provide further parameters, such as a Cancellation.
|
||||||
|
*
|
||||||
|
* @param TConfig $config
|
||||||
|
*
|
||||||
|
* @return TLink
|
||||||
*/
|
*/
|
||||||
public function connect(SqlConfig $config, ?Cancellation $cancellation = null): Link;
|
public function connect(SqlConfig $config, ?Cancellation $cancellation = null): Link;
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,13 @@
|
|||||||
|
|
||||||
namespace Amp\Sql;
|
namespace Amp\Sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template TResult extends Result
|
||||||
|
*/
|
||||||
interface Statement extends TransientResource
|
interface Statement extends TransientResource
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param mixed[] $params
|
* @return TResult
|
||||||
*/
|
*/
|
||||||
public function execute(array $params = []): Result;
|
public function execute(array $params = []): Result;
|
||||||
|
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
namespace Amp\Sql;
|
namespace Amp\Sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template TResult extends Result
|
||||||
|
* @template TStatement extends Statement
|
||||||
|
* @extends Executor<TResult, TStatement>
|
||||||
|
*/
|
||||||
interface Transaction extends Executor
|
interface Transaction extends Executor
|
||||||
{
|
{
|
||||||
public function getIsolationLevel(): TransactionIsolation;
|
public function getIsolationLevel(): TransactionIsolation;
|
||||||
|
Loading…
Reference in New Issue
Block a user