Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Database
✓ import { Database } from 'sqlite-napi'
✗ const Database = require('sqlite-napi').Database
Default export is not available; must use named import. Works with both ES modules and CommonJS.
Statement
✓ import { Statement } from 'sqlite-napi'
✗ import Statement from 'sqlite-napi'
Statement is a named export, not default. TypeScript users should import type if needed: import type { Statement } from 'sqlite-napi'.
Transaction
✓ import { Transaction } from 'sqlite-napi'
✗ const { Transaction } = require('sqlite-napi')
Transaction is available as a named export. CommonJS destructure works but named import is preferred.
SqliteType
✓ import { SqliteType } from 'sqlite-napi/schema'
✗ import { SqliteType } from 'sqlite-napi'
SqliteType is exported from a subpath; version 1.2.0+ moved it to 'sqlite-napi/schema'. Use subpath import.
type Database
✓ import type { Database } from 'sqlite-napi'
For TypeScript type-only imports, use import type syntax to avoid runtime overhead.
Creates an in-memory SQLite database, creates a table, inserts records using positional parameters, queries all rows, prepares a statement to get a single row, and cleans up.
import { Database } from 'sqlite-napi';
const db = new Database(':memory:');
db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
db.exec('INSERT INTO users (name) VALUES (?)', ['Alice']);
db.exec('INSERT INTO users (name) VALUES (?)', ['Bob']);
const users = db.query('SELECT * FROM users').all();
console.log(users);
// ^ [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
const stmt = db.prepare('SELECT * FROM users WHERE id = ?');
const user = stmt.get(1);
console.log(user);
// ^ { id: 1, name: 'Alice' }
stmt.finalize();
db.close();
Errors
Common errors & fixes
TypeError: Database is not a constructor
Using default import instead of named import in CommonJS or ES module context.
fixUse import { Database } from 'sqlite-napi' Cannot find module 'sqlite-napi/schema'
Using older version (<1.2.0) that does not have subpath exports.
fixUpdate to v1.2.0+ or import from main path: import { SqliteType } from 'sqlite-napi' (but this exports type only) Error: unknown database option: readonly
Option name 'readonly' was renamed to 'readwrite' in v1.1.0.
fixUse { readwrite: false } instead of { readonly: true } Error: data type mismatch
Passing a JavaScript object to a WHERE clause expecting scalar value.
fixEnsure SQL parameters are primitive types (string, number, boolean, null, ArrayBuffer).
Audit
Dependencies
bunoptionalOptional peer dependency for Bun compatibility; only needed if using with Bun runtime.