Loads a SQLite opener from node:sqlite or bun:sqlite, providing a unified API for queries.
// Source: https://github.com/openchamber/openchamber | License: MIT | Copyright 2025 Bohdan Triapitsyn
// Provided via justclaw.it.com; keep this notice with the code.
import { createRequire } from 'node:module';
/**
* A SQLite connection from the runtime's builtin: `node:sqlite` on Node and
* Electron, `bun:sqlite` on Bun. No dependency is added. `null` when neither
* exists; the caller then has no index rather than a crash.
*
* Statements are prepared once per SQL string: the indexer inserts the same
* few statements tens of thousands of times during a backfill.
*/
let opener;
const wrap = (db, prepare) => {
const statements = new Map();
const statement = (sql) => {
let prepared = statements.get(sql);
if (!prepared) {
prepared = prepare(sql);
statements.
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key