@photostructure/sqlite provides 100% API compatibility with Node.js's built-in SQLite module. This means you can use it as a drop-in replacement without changing any code.
Simply change your import statement:
// Before: Using Node.js built-in SQLite (requires Node.js 22.5.0+ and --experimental-sqlite flag)
const { DatabaseSync } = require("node:sqlite");
// After: Using @photostructure/sqlite (works on Node.js 20+ without any flags)
const { DatabaseSync } = require("@photostructure/sqlite");
Or with ES modules:
// Before
import { DatabaseSync } from "node:sqlite";
// After
import { DatabaseSync } from "@photostructure/sqlite";
That's it! All your existing code will work exactly the same.
# Node.js built-in requires:
node --experimental-sqlite app.js
# @photostructure/sqlite works directly:
node app.js
All classes, methods, and properties are identical:
DatabaseSync
class with all the same methodsStatementSync
class with identical behavior// This code works identically with both libraries
const { DatabaseSync, StatementSync } = require("@photostructure/sqlite");
// OR: const { DatabaseSync, StatementSync } = require('node:sqlite');
const db = new DatabaseSync(":memory:");
// Create tables
db.exec(`
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE
)
`);
// Prepared statements
const insert = db.prepare("INSERT INTO users (name, email) VALUES (?, ?)");
const result = insert.run("Alice", "alice@example.com");
console.log(result.lastInsertRowid);
// Queries
const users = db.prepare("SELECT * FROM users").all();
console.log(users);
// Custom functions
db.function("uppercase", (str) => str.toUpperCase());
const upper = db.prepare("SELECT uppercase(name) as name FROM users").get();
console.log(upper.name); // ALICE
// Cleanup
db.close();
npm install @photostructure/sqlite
'node:sqlite'
to '@photostructure/sqlite'
--experimental-sqlite
flag from your npm scriptsYou might want to stick with the built-in module if:
Choose this package when:
When node:sqlite
becomes stable (removes the experimental flag), migrating back is trivial:
// Simply change the import back
import { DatabaseSync } from "node:sqlite";
// All your code continues to work unchanged
This makes @photostructure/sqlite a perfect bridge solution while waiting for the official module to stabilize.