Skip to content

Commit

Permalink
fix: added stream function to Database class
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasHaderer committed Mar 1, 2024
1 parent a62d096 commit a4b9b60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/duckdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/query_result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit a4b9b60

Please sign in to comment.