1
0
mirror of https://github.com/danog/postgres.git synced 2024-11-27 04:24:45 +01:00
postgres/lib/PqStatement.php
Aaron Piotrowski f1b1f0070d
Remove unneeded storage of name in PqStatement
The \pq\Statement object contains a name field.
2017-07-28 17:34:43 -05:00

53 lines
1.1 KiB
PHP

<?php
namespace Amp\Postgres;
use Amp\Promise;
use pq;
class PqStatement implements Statement {
/** @var \pq\Statement */
private $statement;
/** @var callable */
private $execute;
/** @var callable */
private $deallocate;
/**
* @internal
*
* @param \pq\Statement $statement
* @param callable $execute
* @param callable $deallocate
*/
public function __construct(pq\Statement $statement, callable $execute, callable $deallocate) {
$this->statement = $statement;
$this->execute = $execute;
$this->deallocate = $deallocate;
}
public function __destruct() {
($this->deallocate)($this->statement->name);
}
/**
* @return string
*/
public function getQuery(): string {
return $this->statement->query;
}
/**
* @param mixed ...$params
*
* @return \Amp\Promise<\Amp\Postgres\Result>
*
* @throws \Amp\Postgres\FailureException If executing the statement fails.
*/
public function execute(...$params): Promise {
return ($this->execute)([$this->statement, "execAsync"], $params);
}
}