JavaScript
npm i sqlite-graft
pnpm add sqlite-graft
yarn add sqlite-graft
To use Graft with Node.js’s built-in SQLite module, Node.js version 23.10.0 or later is required, as this is the first version that supports URI-formatted database connections needed by Graft.
import * as sqliteGraft from "sqlite-graft";// Also should work with other javascript SQLite libraries:import { DatabaseSync } from "node:sqlite";
// load the graft extensionlet db = new DatabaseSync(":memory:", { allowExtension: true });sqliteGraft.load(db);
// open a Graft volume as a database and run graft_statusdb = new DatabaseSync("file:random?vfs=graft");let result = db.prepare("PRAGMA graft_status");console.log(result.all());
You can also use Graft with better-sqlite3
and older versions of Node by setting the environment variable GRAFT_MAKE_DEFAULT=true
. This will cause Graft to register itself as the default VFS for all new SQLite connections, so no URI path required.