| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d86ff60 commit 3a6bd9c
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -375,7 +375,10 @@ class CustomAggregate { | |||
| 375 | 375 | result = Local<Value>::New(isolate, agg->value); | |
| 376 | 376 | } | |
| 377 | 377 | ||
| 378 | - JSValueToSQLiteResult(isolate, ctx, result); | ||
| 378 | + if (!result.IsEmpty()) { | ||
| 379 | + JSValueToSQLiteResult(isolate, ctx, result); | ||
| 380 | + } | ||
| 381 | + | ||
| 379 | 382 | if (is_final) { | |
| 380 | 383 | DestroyAggregateData(ctx); | |
| 381 | 384 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -309,6 +309,27 @@ describe('step', () => { | |||
| 309 | 309 | }); | |
| 310 | 310 | ||
| 311 | 311 | describe('result', () => { | |
| 312 | + test('throws if result throws an error', (t) => { | ||
| 313 | + const db = new DatabaseSync(':memory:'); | ||
| 314 | + t.after(() => db.close()); | ||
| 315 | + db.exec('CREATE TABLE data (value INTEGER)'); | ||
| 316 | + db.exec('INSERT INTO data VALUES (1), (2), (3)'); | ||
| 317 | + db.aggregate('sum_int', { | ||
| 318 | + start: 0, | ||
| 319 | + step: (acc, value) => { | ||
| 320 | + return acc + value; | ||
| 321 | + }, | ||
| 322 | + result: () => { | ||
| 323 | + throw new Error('result error'); | ||
| 324 | + }, | ||
| 325 | + }); | ||
| 326 | + t.assert.throws(() => { | ||
| 327 | + db.prepare('SELECT sum_int(value) as result FROM data').get(); | ||
| 328 | + }, { | ||
| 329 | + message: 'result error' | ||
| 330 | + }); | ||
| 331 | + }); | ||
| 332 | + | ||
| 312 | 333 | test('executes once when options.inverse is not present', (t) => { | |
| 313 | 334 | const db = new DatabaseSync(':memory:'); | |
| 314 | 335 | t.after(() => db.close()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments