1
0
mirror of https://github.com/danog/postgres.git synced 2024-12-15 19:07:26 +01:00
postgres/lib/PqBufferedResult.php

32 lines
712 B
PHP
Raw Normal View History

2016-12-30 06:21:17 +01:00
<?php
2016-09-14 16:27:39 +02:00
namespace Amp\Postgres;
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;
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;
}
}