Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ class CustomAggregate {
result = Local<Value>::New(isolate, agg->value);
}

JSValueToSQLiteResult(isolate, ctx, result);
if (!result.IsEmpty()) {
JSValueToSQLiteResult(isolate, ctx, result);
}

if (is_final) {
DestroyAggregateData(ctx);
}
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-sqlite-aggregate-function.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,27 @@ describe('step', () => {
});

describe('result', () => {
test('throws if result throws an error', (t) => {
const db = new DatabaseSync(':memory:');
t.after(() => db.close());
db.exec('CREATE TABLE data (value INTEGER)');
db.exec('INSERT INTO data VALUES (1), (2), (3)');
db.aggregate('sum_int', {
start: 0,
step: (acc, value) => {
return acc + value;
},
result: () => {
throw new Error('result error');
},
});
t.assert.throws(() => {
db.prepare('SELECT sum_int(value) as result FROM data').get();
}, {
message: 'result error'
});
});

test('executes once when options.inverse is not present', (t) => {
const db = new DatabaseSync(':memory:');
t.after(() => db.close());
Expand Down
Loading