2016-12-30 06:21:17 +01:00
|
|
|
<?php
|
2016-09-14 16:27:39 +02:00
|
|
|
|
|
|
|
namespace Amp\Postgres;
|
|
|
|
|
2017-03-17 16:17:24 +01:00
|
|
|
use Amp\{ Coroutine, Promise };
|
2016-09-14 16:27:39 +02:00
|
|
|
use pq;
|
|
|
|
|
|
|
|
class PqStatement implements Statement {
|
|
|
|
/** @var \pq\Statement */
|
|
|
|
private $statement;
|
|
|
|
|
|
|
|
/** @var callable */
|
|
|
|
private $execute;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \pq\Statement $statement
|
|
|
|
* @param callable $execute
|
|
|
|
*/
|
|
|
|
public function __construct(pq\Statement $statement, callable $execute) {
|
|
|
|
$this->statement = $statement;
|
|
|
|
$this->execute = $execute;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __destruct() {
|
2017-03-17 16:17:24 +01:00
|
|
|
Promise\rethrow(new Coroutine(($this->execute)([$this->statement, "deallocateAsync"])));
|
2016-09-14 16:27:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getQuery(): string {
|
|
|
|
return $this->statement->query;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed ...$params
|
|
|
|
*
|
2017-03-17 16:17:24 +01:00
|
|
|
* @return \Amp\Promise<\Amp\Postgres\Result>
|
2016-09-14 16:27:39 +02:00
|
|
|
*
|
|
|
|
* @throws \Amp\Postgres\FailureException If executing the statement fails.
|
|
|
|
*/
|
2016-11-15 18:06:21 +01:00
|
|
|
public function execute(...$params): Promise {
|
2016-09-14 16:27:39 +02:00
|
|
|
return new Coroutine(($this->execute)([$this->statement, "execAsync"], $params));
|
|
|
|
}
|
|
|
|
}
|