2016-09-14 09:27:39 -05:00
|
|
|
<?php declare(strict_types = 1);
|
|
|
|
|
|
|
|
namespace Amp\Postgres;
|
|
|
|
|
2016-11-15 11:06:21 -06:00
|
|
|
use Interop\Async\Promise;
|
2016-09-14 09:27:39 -05:00
|
|
|
|
|
|
|
class PgSqlStatement implements Statement {
|
|
|
|
/** @var string */
|
|
|
|
private $sql;
|
|
|
|
|
|
|
|
/** @var callable */
|
|
|
|
private $execute;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $sql
|
|
|
|
* @param callable $execute
|
|
|
|
*/
|
|
|
|
public function __construct(string $sql, callable $execute) {
|
|
|
|
$this->sql = $sql;
|
|
|
|
$this->execute = $execute;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getQuery(): string {
|
|
|
|
return $this->sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed ...$params
|
|
|
|
*
|
2016-11-15 11:06:21 -06:00
|
|
|
* @return \Interop\Async\Promise<\Amp\Postgres\Result>
|
2016-09-14 09:27:39 -05:00
|
|
|
*
|
|
|
|
* @throws \Amp\Postgres\FailureException If executing the statement fails.
|
|
|
|
*/
|
2016-11-15 11:06:21 -06:00
|
|
|
public function execute(...$params): Promise {
|
2016-09-14 09:27:39 -05:00
|
|
|
return ($this->execute)($this->sql, $params);
|
|
|
|
}
|
|
|
|
}
|