diff --git a/lib/duckdb.js b/lib/duckdb.js index fc760d2f..63d00207 100644 --- a/lib/duckdb.js +++ b/lib/duckdb.js @@ -530,6 +530,17 @@ Database.prototype.each = function () { return this; } + +/** + * @arg sql + * @param {...*} params + * @yields row chunks + */ +Database.prototype.stream = function() { + return default_connection(this).stream.apply(this.default_connection, arguments); +} + + /** * Convenience method for Connection#apply using a built-in default connection * @arg sql diff --git a/test/query_result.test.ts b/test/query_result.test.ts index 16eb231c..8f8d174c 100644 --- a/test/query_result.test.ts +++ b/test/query_result.test.ts @@ -20,4 +20,13 @@ describe('QueryResult', () => { } assert.equal(total, retrieved) }) + + it('streams results using the database object', async () => { + let retrieved = 0; + const stream = db.stream('SELECT * FROM range(0, ?)', total); + for await (const row of stream) { + retrieved++; + } + assert.equal(total, retrieved) + }) })