From 32109ab1d3f5ff79afc13cd65e3297bbb57e5bc2 Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Mon, 14 Nov 2022 19:37:34 +0000 Subject: [PATCH] Make Result iterable Make `Result` automatically iterable, so one can iterate through data without having to access `rows` explicitly: ```js client.query('select...', (err, res) => { // below we can use just "res", not "res.rows" for(const a of res) { console.log(a); // print the row } }) ``` --- packages/pg/lib/result.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/pg/lib/result.js b/packages/pg/lib/result.js index 350609743..5479b84ae 100644 --- a/packages/pg/lib/result.js +++ b/packages/pg/lib/result.js @@ -23,6 +23,10 @@ class Result { } } + [Symbol.iterator]() { + return this.rows.values() + } + // adds a command complete message addCommandComplete(msg) { var match