From ab7b0dd1aabea5895db9dc904d6f41a79d4836f7 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 7 Aug 2025 14:25:59 +0300 Subject: [PATCH] bindings/javascript: Implement Statement.iterate() --- bindings/javascript/promise.js | 19 +++++++++++++++++-- bindings/javascript/sync.js | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/bindings/javascript/promise.js b/bindings/javascript/promise.js index cd8d4d702..e23c8ac9d 100644 --- a/bindings/javascript/promise.js +++ b/bindings/javascript/promise.js @@ -320,8 +320,23 @@ class Statement { * * @param bindParameters - The bind parameters for executing the statement. */ - *iterate(...bindParameters) { - throw new Error("not implemented"); + async *iterate(...bindParameters) { + this.stmt.reset(); + bindParams(this.stmt, bindParameters); + + while (true) { + const stepResult = this.stmt.step(); + if (stepResult === STEP_IO) { + await this.db.db.ioLoopAsync(); + continue; + } + if (stepResult === STEP_DONE) { + break; + } + if (stepResult === STEP_ROW) { + yield this.stmt.row(); + } + } } /** diff --git a/bindings/javascript/sync.js b/bindings/javascript/sync.js index a3bd934fc..759b8d729 100644 --- a/bindings/javascript/sync.js +++ b/bindings/javascript/sync.js @@ -319,7 +319,22 @@ class Statement { * @param bindParameters - The bind parameters for executing the statement. */ *iterate(...bindParameters) { - throw new Error("not implemented"); + this.stmt.reset(); + bindParams(this.stmt, bindParameters); + + while (true) { + const stepResult = this.stmt.step(); + if (stepResult === STEP_IO) { + this.db.db.ioLoopSync(); + continue; + } + if (stepResult === STEP_DONE) { + break; + } + if (stepResult === STEP_ROW) { + yield this.stmt.row(); + } + } } /**