Registry / database / sqlite-napi

sqlite-napi

JSON →
library1.3.0jsnpmunverified

High-performance SQLite library for Node.js (>=18) and Bun (>=1.0) that closely mirrors the bun:sqlite API. Built with Rust using NAPI-RS for native speed. Current stable version is 1.3.0. Key differentiators: drop-in replacement for bun:sqlite on Node.js, TypeScript types included, supports custom functions, collations, schema introspection, migrations, serialization, and extensions. Active development on GitHub.

npm install sqlite-napi
INSTALL
IMPORT
SIG · SQLITE-NAPI
S
sqlite-napi
databasejavascriptv1.3.0
harness data pending
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();
Debug
Known issues
breakingDatabase constructor no longer accepts options object with 'readonly' property (removed in v1.1.0). Use 'readwrite' instead.
fix
Replace new Database(path, { readonly: true }) with new Database(path, { readwrite: false })
affects: >=1.1.0
deprecatedStatement.columns() method is deprecated as of v1.2.0. Use Database.getColumns() instead.
fix
Replace stmt.columns() with db.getColumns(tableName)
affects: >=1.2.0
gotchaNamed parameters expect a colon prefix (e.g., :name). Bun's sqlite accepts both $ and :, but sqlite-napi requires colon.
fix
Use :param in SQL strings instead of $param.
affects: >=0.1.0
gotchaTransaction objects must be explicitly committed or rolled back; otherwise, changes are discarded when the database closes.
fix
Always call trans.commit() or trans.rollback() after using a transaction.
affects: >=0.1.0
breakingRemoved second parameter (values) from Database.exec() in v1.0.0. Use Database.run() for parameterized queries.
fix
Replace db.exec('SQL', [params]) with db.run('SQL', [params])
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Database is not a constructor
Using default import instead of named import in CommonJS or ES module context.
fix
Use import { Database } from 'sqlite-napi'
Cannot find module 'sqlite-napi/schema'
Using older version (<1.2.0) that does not have subpath exports.
fix
Update 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.
fix
Use { readwrite: false } instead of { readonly: true }
Error: data type mismatch
Passing a JavaScript object to a WHERE clause expecting scalar value.
fix
Ensure SQL parameters are primitive types (string, number, boolean, null, ArrayBuffer).
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
bunoptionalOptional peer dependency for Bun compatibility; only needed if using with Bun runtime.
Agent activity
11 hits · last 30 days
node
8
Meta
2
OpenAI (training)
1
Resources
sqlite-napi — npm install sqlite-napi · libregistry