Scalar functions
Create row-by-row transformations and calculations in JavaScript.
Programmable SQLite
Extend SQLite with scalar functions, aggregates, window functions, collations, and JavaScript evaluation.
SQLite-JS
SQLite-native extension
Best for
Custom SQL functions and logic
Repository
GitHubProject
SQLite-JS embeds JavaScript into SQLite so developers can define reusable database logic with familiar code and call it from SQL.
It is useful when application behavior, transformations, scoring, validation, or custom ordering need to travel with the local database rather than live in one backend service.
Why it matters
Capabilities
Create row-by-row transformations and calculations in JavaScript.
Compute grouped results such as custom medians, scores, or reducers.
Use JavaScript logic over SQL windows without collapsing result rows.
Define custom text ordering for application-specific sorting.
Evaluate JavaScript snippets from SQL for flexible embedded computation.
Use native builds plus Swift, Android, Node.js, Flutter, and Dart packages.
Sample code
Register custom JavaScript once, then use it like any other SQLite function.
-- Load SQLite-JS
.load ./js
SELECT js_create_scalar('age', '(function(args) {
const birthDate = new Date(args[0]);
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
})');
SELECT name, age(birth_date) AS age
FROM people;