Skip to content

Commit

Permalink
API Update PostgreSQLQuery to use generators
Browse files Browse the repository at this point in the history
  • Loading branch information
kinglozzer authored and GuySartorelli committed Aug 11, 2022
1 parent 7879295 commit c01dd6a
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions code/PostgreSQLQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\PostgreSQL;

use Iterator;
use SilverStripe\ORM\Connect\Query;

/**
Expand Down Expand Up @@ -56,31 +57,18 @@ public function __destruct()
}
}

public function seek($row)
public function getIterator(): Iterator
{
// Specifying the zero-th record here will reset the pointer
$result = pg_fetch_array($this->handle, $row, PGSQL_NUM);

return $this->parseResult($result);
while ($row = pg_fetch_array($this->handle, null, PGSQL_NUM)) {
yield $this->parseResult($row);
}
}

public function numRecords()
{
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
* @return array
Expand Down

0 comments on commit c01dd6a

Please sign in to comment.