Image Image

Programmable SQLite

Create custom SQLite functions in JavaScript.

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

GitHub

Project

What it is

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

Push logic
to the edge.

Edge and offline-first apps need local business logic as much as local data. SQLite-JS lets you ship that logic inside the database runtime.
When paired with SQLite Sync, function definitions can be distributed to clients so the same behavior is available across devices and agents.

Capabilities

Features and characteristics

Scalar functions

Create row-by-row transformations and calculations in JavaScript.

Aggregate functions

Compute grouped results such as custom medians, scores, or reducers.

Window functions

Use JavaScript logic over SQL windows without collapsing result rows.

Collations

Define custom text ordering for application-specific sorting.

JavaScript evaluation

Evaluate JavaScript snippets from SQL for flexible embedded computation.

Multi-runtime packages

Use native builds plus Swift, Android, Node.js, Flutter, and Dart packages.

Sample code

Define a JavaScript function and query it

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;
Subscribe to our newsletter
The latest news, articles, and resources, sent to your inbox.

© 2026 SQLite Cloud, Inc. All rights reserved.