Added get_pairs_iterable to database object

This commit is contained in:
Matthew Barbour 2020-10-08 16:58:57 -05:00
parent 81af2e99f8
commit 0fc0b8e723

View file

@ -258,6 +258,20 @@ class Database
return $res;
}
/**
* Execute an SQL query and return the the first column => the second column as an iterable object.
*/
public function get_pairs_iterable(string $query, array $args = []): Generator
{
$_start = microtime(true);
$stmt = $this->execute($query, $args);
$this->count_time("get_pairs_iterable", $_start, $query, $args);
foreach ($stmt as $row) {
yield $row[0] => $row[1];
}
}
/**
* Execute an SQL query and return a single value, or null.
*/