2016-12-30 06:21:17 +01:00
|
|
|
<?php
|
2016-09-14 16:27:39 +02:00
|
|
|
|
|
|
|
namespace Amp\Postgres;
|
|
|
|
|
2017-01-18 18:05:05 +01:00
|
|
|
use Amp\Producer;
|
2016-09-14 16:27:39 +02:00
|
|
|
use pq;
|
|
|
|
|
2017-05-16 06:14:02 +02:00
|
|
|
class PqBufferedResult extends TupleResult {
|
2016-09-14 16:27:39 +02:00
|
|
|
/** @var \pq\Result */
|
|
|
|
private $result;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param pq\Result $result PostgreSQL result object.
|
|
|
|
*/
|
|
|
|
public function __construct(pq\Result $result) {
|
|
|
|
$this->result = $result;
|
2017-01-18 18:05:05 +01:00
|
|
|
parent::__construct(new Producer(static function (callable $emit) use ($result) {
|
2017-05-16 06:14:02 +02:00
|
|
|
while ($row = $result->fetchRow(pq\Result::FETCH_ASSOC)) {
|
2016-09-14 16:27:39 +02:00
|
|
|
yield $emit($row);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2017-05-16 06:28:37 +02:00
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
public function numRows(): int {
|
|
|
|
return $this->result->numRows;
|
|
|
|
}
|
2017-05-16 06:28:37 +02:00
|
|
|
|
2016-09-14 16:27:39 +02:00
|
|
|
public function numFields(): int {
|
|
|
|
return $this->result->numCols;
|
|
|
|
}
|
|
|
|
}
|