1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-16 11:27:14 +01:00
postgres/lib/PqBufferedResult.php
Aaron Piotrowski caf829a48c Initial commit
2016-09-14 09:27:39 -05:00

37 lines
893 B
PHP

<?php declare(strict_types = 1);
namespace Amp\Postgres;
use Amp\Emitter;
use pq;
class PqBufferedResult extends TupleResult implements \Countable {
/** @var \pq\Result */
private $result;
/**
* @param pq\Result $result PostgreSQL result object.
*/
public function __construct(pq\Result $result) {
$this->result = $result;
parent::__construct(new Emitter(static function (callable $emit) use ($result) {
for ($count = 0; $row = $result->fetchRow(pq\Result::FETCH_ASSOC); ++$count) {
yield $emit($row);
}
return $count;
}));
}
public function numRows(): int {
return $this->result->numRows;
}
public function numFields(): int {
return $this->result->numCols;
}
public function count(): int {
return $this->numRows();
}
}