Skip to content

Commit 4a1c632

Browse files
committed
Add template types to most interfaces
1 parent 3060e7f commit 4a1c632

6 files changed

Lines changed: 51 additions & 2 deletions

File tree

src/Executor.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
namespace Amp\Sql;
44

5+
/**
6+
* @template TResult extends Result
7+
* @template TStatement extends Statement
8+
*/
59
interface Executor extends TransientResource
610
{
711
/**
812
* @param string $sql SQL query to execute.
913
*
14+
* @return TResult
15+
*
1016
* @throws SqlException If the operation fails due to unexpected condition.
1117
* @throws ConnectionException If the connection to the database is lost.
1218
* @throws QueryError If the operation fails due to an error in the query (such as a syntax error).
@@ -16,6 +22,8 @@ public function query(string $sql): Result;
1622
/**
1723
* @param string $sql SQL query to prepare.
1824
*
25+
* @return TStatement
26+
*
1927
* @throws SqlException If the operation fails due to unexpected condition.
2028
* @throws ConnectionException If the connection to the database is lost.
2129
* @throws QueryError If the operation fails due to an error in the query (such as a syntax error).
@@ -26,9 +34,16 @@ public function prepare(string $sql): Statement;
2634
* @param string $sql SQL query to prepare and execute.
2735
* @param mixed[] $params Query parameters.
2836
*
37+
* @return TResult
38+
*
2939
* @throws SqlException If the operation fails due to unexpected condition.
3040
* @throws ConnectionException If the connection to the database is lost.
3141
* @throws QueryError If the operation fails due to an error in the query (such as a syntax error).
3242
*/
3343
public function execute(string $sql, array $params = []): Result;
44+
45+
/**
46+
* Closes the executor. No further queries may be performed.
47+
*/
48+
public function close(): void;
3449
}

src/Link.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
namespace Amp\Sql;
44

5+
/**
6+
* @template TResult extends Result
7+
* @template TStatement extends Statement
8+
* @template TTransaction extends Transaction
9+
*
10+
* @extends Executor<TResult, TStatement>
11+
*/
512
interface Link extends Executor
613
{
714
/**
815
* Starts a transaction on a single connection.
916
*
10-
* @param TransactionIsolation $isolation Transaction isolation level.
17+
* @param TransactionIsolation $isolation Transaction isolation level.'
18+
*
19+
* @return TTransaction
1120
*/
1221
public function beginTransaction(
1322
TransactionIsolation $isolation = TransactionIsolationLevel::Committed,

src/Pool.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22

33
namespace Amp\Sql;
44

5+
/**
6+
* @template TResult extends Result
7+
* @template TStatement extends Statement
8+
* @template TTransaction extends Transaction
9+
*
10+
* @extends Link<TResult, TStatement, TTransaction>
11+
*/
512
interface Pool extends Link
613
{
714
/**
815
* Gets a single connection from the pool to run a set of queries against a single connection.
916
* Generally a transaction should be used instead of this method.
17+
*
18+
* @return Link<TResult, TStatement, TTransaction>
1019
*/
1120
public function extractConnection(): Link;
1221

src/SqlConnector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
use Amp\Cancellation;
66

7+
/**
8+
* @template TConfig extends SqlConfig
9+
* @template TLink extends Link
10+
*/
711
interface SqlConnector
812
{
913
/**
1014
* Returns a new database connection based on the given configuration.
1115
* Implementations may provide further parameters, such as a Cancellation.
16+
*
17+
* @param TConfig $config
18+
*
19+
* @return TLink
1220
*/
1321
public function connect(SqlConfig $config, ?Cancellation $cancellation = null): Link;
1422
}

src/Statement.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
namespace Amp\Sql;
44

5+
/**
6+
* @template TResult extends Result
7+
*/
58
interface Statement extends TransientResource
69
{
710
/**
8-
* @param mixed[] $params
11+
* @return TResult
912
*/
1013
public function execute(array $params = []): Result;
1114

src/Transaction.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
namespace Amp\Sql;
44

5+
/**
6+
* @template TResult extends Result
7+
* @template TStatement extends Statement
8+
* @extends Executor<TResult, TStatement>
9+
*/
510
interface Transaction extends Executor
611
{
712
public function getIsolationLevel(): TransactionIsolation;

0 commit comments

Comments
 (0)