From 0fc0b8e723cc90d86d8a8d98d7e551167824ddec Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Thu, 8 Oct 2020 16:58:57 -0500 Subject: [PATCH] Added get_pairs_iterable to database object --- core/database.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/database.php b/core/database.php index ea3ac36f..f9effb9a 100644 --- a/core/database.php +++ b/core/database.php @@ -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. */