Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ public function allGroup($uniq = false, $callable = null)
return $this->statement->fetchAll($fetchStyle | PDO::FETCH_FUNC, $callable);
}

/**
* Return a generator that fetches each row at a time, reducing memory load.
*
* @param int $fetchStyle (optional) PDO fetch style
*
* @return iterable
*/
public function lazy($fetchStyle = 0)
{
$generator = function() use (&$fetchStyle) {
while($row = $this->statement->fetch($fetchStyle)) {
yield $row;
}
};

return $generator();
}

/**
* Fetch first result
*
Expand Down