Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed Operation from Statement.
- Loading branch information
Showing
11 changed files
with
226 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Amp\Postgres; | ||
|
||
use Amp\Promise; | ||
use function Amp\call; | ||
|
||
class PooledStatement implements Statement { | ||
/** @var \Amp\Postgres\Pool */ | ||
private $pool; | ||
|
||
/** @var \Amp\Postgres\Statement */ | ||
private $statement; | ||
|
||
/** | ||
* @param \Amp\Postgres\Pool $pool Pool used to re-create the statement if the original closes. | ||
* @param \Amp\Postgres\Statement $statement | ||
*/ | ||
public function __construct(Pool $pool, Statement $statement) { | ||
$this->statement = $statement; | ||
$this->pool = $pool; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* Unlike regular statements, as long as the pool is open this statement will not die. | ||
*/ | ||
public function execute(array $params = []): Promise { | ||
if ($this->statement->isAlive()) { | ||
return $this->statement->execute($params); | ||
} | ||
|
||
return call(function () use ($params) { | ||
$this->statement = yield $this->pool->prepare($this->statement->getQuery()); | ||
return yield $this->statement->execute($params); | ||
}); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function isAlive(): bool { | ||
return $this->pool->isAlive(); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getQuery(): string { | ||
return $this->statement->getQuery(); | ||
} | ||
} |
Oops, something went wrong.