Merge pull request #135 from creative-commoners/pulls/3/rescue-master-generators

API Rescue Master Branch PR: Update PostgreSQLQuery to use generators
This commit is contained in:
Steve Boyd 2022-09-01 09:08:20 +12:00 committed by GitHub
commit 0c2d67443a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
namespace SilverStripe\PostgreSQL; namespace SilverStripe\PostgreSQL;
use Iterator;
use SilverStripe\ORM\Connect\Query; use SilverStripe\ORM\Connect\Query;
/** /**
@ -56,12 +57,11 @@ class PostgreSQLQuery extends Query
} }
} }
public function seek($row) public function getIterator(): Iterator
{ {
// Specifying the zero-th record here will reset the pointer while ($row = pg_fetch_array($this->handle, null, PGSQL_NUM)) {
$result = pg_fetch_array($this->handle, $row, PGSQL_NUM); yield $this->parseResult($row);
}
return $this->parseResult($result);
} }
public function numRecords() public function numRecords()
@ -69,18 +69,6 @@ class PostgreSQLQuery extends Query
return pg_num_rows($this->handle); return pg_num_rows($this->handle);
} }
public function nextRecord()
{
$row = pg_fetch_array($this->handle, null, PGSQL_NUM);
// Correct non-string types
if ($row) {
return $this->parseResult($row);
}
return false;
}
/** /**
* @param array $row * @param array $row
* @return array * @return array