Registers a new aggregate function with the SQLite database. This method is a wrapper around sqlite3_create_window_function()
.
When used as a window function, the result
function will be called multiple times.
import { DatabaseSync } from 'node:sqlite';
const db = new DatabaseSync(':memory:');
db.exec(`
CREATE TABLE t3(x, y);
INSERT INTO t3 VALUES ('a', 4),
('b', 5),
('c', 3),
('d', 8),
('e', 1);
`);
db.aggregate('sumint', {
start: 0,
step: (acc, value) => acc + value,
});
db.prepare('SELECT sumint(y) as total FROM t3').get(); // { total: 21 }