Skip to content

Commit

Permalink
Merge pull request #54 from NiclasHaderer/fix-stream-function
Browse files Browse the repository at this point in the history
Fixes Database.stream is not a function exception
  • Loading branch information
Mytherin authored May 28, 2024
2 parents d886b3e + a4b9b60 commit 5b5f7d5
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 5b5f7d5

Please sign in to comment.