Skip to content

Commit 6bf7aea

Browse files
committed
optimize queryRow
1 parent a0fef0c commit 6bf7aea

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/duckdb.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ export class DuckDBClient {
8484
}
8585

8686
async queryRow(query, params) {
87-
const results = await this.query(query, params);
88-
return results.length ? results[0] : null;
87+
const result = await this.queryStream(query, params);
88+
const reader = result.readRows();
89+
try {
90+
const {done, value} = await reader.next();
91+
return done || !value.length ? null : value[0];
92+
} finally {
93+
await reader.return();
94+
}
8995
}
9096

9197
async sql(strings, ...args) {

0 commit comments

Comments
 (0)