Extract TransientResource interface

This commit is contained in:
Chris Wright 2018-07-09 08:55:12 +01:00 committed by Aaron Piotrowski
parent 130bcb5c10
commit 15c2090945
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 22 additions and 24 deletions

View File

@ -4,7 +4,7 @@ namespace Amp\Sql;
use Amp\Promise;
interface Executor
interface Executor extends TransientResource
{
/**
* @param string $sql SQL query to execute.
@ -40,18 +40,6 @@ interface Executor
*/
public function execute(string $sql, array $params = []): Promise;
/**
* Indicates if the connection to the database is still alive.
*
* @return bool
*/
public function isAlive(): bool;
/**
* @return int Timestamp of the last time this connection was used.
*/
public function lastUsedAt(): int;
/**
* Closes the executor. No further queries may be performed.
*/

View File

@ -4,7 +4,7 @@ namespace Amp\Sql;
use Amp\Promise;
interface Statement
interface Statement extends TransientResource
{
/**
* @param mixed[] $params
@ -13,18 +13,8 @@ interface Statement
*/
public function execute(array $params = []): Promise;
/**
* @return bool True if the statement can still be executed, false if the connection has died.
*/
public function isAlive(): bool;
/**
* @return string The SQL string used to prepare the statement.
*/
public function getQuery(): string;
/**
* @return int Timestamp of when the statement was last used.
*/
public function lastUsedAt(): int;
}

20
src/TransientResource.php Normal file
View File

@ -0,0 +1,20 @@
<?php
namespace Amp\Sql;
interface TransientResource
{
/**
* Indicates if the resource is still valid.
*
* @return bool
*/
public function isAlive(): bool;
/**
* Get the timestamp of the last usage of this resource.
*
* @return int
*/
public function lastUsedAt(): int;
}