Skip to content

Commit

Permalink
refactor: run cursor transaction outside
Browse files Browse the repository at this point in the history
  • Loading branch information
darkterminal committed Jul 13, 2024
1 parent 44e7e96 commit 48608aa
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/Database/LibSQLConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,17 @@ public function selectResultSets($query, $bindings = [], $useReadPdo = true)
*/
public function cursor($query, $bindings = [], $useReadPdo = true)
{
$statement = $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) {
return [];
}

$preparedQuery = $this->getRawPdo()->prepare($query);
if ($this->pretending()) {
return [];
}

if (! $preparedQuery) {
throw new Exception('Failed to prepare statement.');
}
$preparedQuery = $this->getRawPdo()->prepare($query);

$results = $preparedQuery->query($this->prepareBindings($bindings))->fetchArray(LibSQL::LIBSQL_ASSOC);
if (! $preparedQuery) {
throw new Exception('Failed to prepare statement.');
}

return $results;
});
$statement = $preparedQuery->query($bindings)->fetchArray(LibSQL::LIBSQL_ASSOC);

foreach ($statement as $record) {
yield $record;
Expand Down

0 comments on commit 48608aa

Please sign in to comment.