Registry / database / sqlite-async

sqlite-async

JSON →
library1.2.2jsnpmunverified

ES6 Promise-based interface to the sqlite3 module. Version 1.2.2 is stable and unmaintained since 2020. It wraps every method of the node-sqlite3 synchronous callback API into a Promise-returning equivalent, supporting Database and Statement classes. Unlike alternatives like better-sqlite3 (synchronous) or sql.js (WebAssembly), it is a thin wrapper over the popular but callback-heavy node-sqlite3, adding no new features beyond promise conversion. Release cadence: last updated in 2020, likely maintenance mode. Key differentiator: minimal API, exactly matches sqlite3 method signatures.

npm install sqlite-async
INSTALL
IMPORT
SIG · SQLITE-ASYNC
S
sqlite-async
databasejavascriptv1.2.2
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-async'
import Database from 'sqlite-async'
The module exports Database as a named export, not default.
Database
const { Database } = require('sqlite-async')
const Database = require('sqlite-async')
CJS destructuring is required; it's not a default export.
Statement
import { Statement } from 'sqlite-async'
Statement is also exported as a named export, though typically obtained via db.prepare()
Database
import { Database } from 'sqlite-async'
import * as sqlite from 'sqlite-async'; const Database = sqlite.Database;
Using namespace import is valid but unnecessarily verbose.

Opens an in-memory SQLite database, creates a table, inserts a row, and retrieves it using async/await.

import { Database } from 'sqlite-async'; async function main() { try { const db = await Database.open(':memory:'); await db.run('CREATE TABLE test (id INT, name TEXT)'); await db.run('INSERT INTO test VALUES (?, ?)', [1, 'Alice']); const row = await db.get('SELECT * FROM test WHERE id = 1'); console.log('Row:', row); await db.close(); } catch (err) { console.error('Error:', err); } } main();
Debug
Known issues
gotchaThe `close()` method accepts an optional function argument that must return a promise, but beginners may pass a non-promise function causing unresolved promises.
fix
Ensure the function passed to close() returns a promise: db.close(() => { return somePromise(); })
affects: >=1.0.0
gotchaThe `transaction()` method does not support nested transactions and may silently break if a user attempts to call it inside a transaction callback.
fix
Do not nest transaction calls. Use savepoints manually if needed.
affects: >=1.0.0
gotchaThe `each()` method requires a callback as the third argument, which is unlike other methods that return promises. Missing the callback will cause a promise rejection with 'Missing callback' error.
fix
Always pass a callback function to each(): db.each(sql, [], row => { ... })
affects: >=1.0.0
deprecatedDepends on node-sqlite3 v5+ which has breaking changes in build system; prebuilt binaries may not be available for all platforms.
fix
Use environment variable npm_config_build_from_source=true if prebuilt binaries fail.
affects: >=1.2.0
Errors
Common errors & fixes
Error: Cannot find module 'sqlite3'
sqlite3 is a peer dependency that must be installed manually.
fix
npm install sqlite3
node:internal/process/promises:227 triggerUncaughtException(err, true /* fromPromise */)
Error thrown inside an async function without catch handler.
fix
Wrap async operations in try/catch or add .catch() to the promise chain.
TypeError: db.close is not a function
Using a Database instance that has not been opened (import default mistake).
fix
Ensure you use Database.open() and not a direct new Database() which is not supported.
SQLITE_ERROR: cannot start a transaction within a transaction
Calling db.transaction() inside another db.transaction() callback.
fix
Restructure code to use a single transaction or use SAVEPOINT.
Upgrade
Version history
1.2.2latest on npm
Audit
Dependencies
sqlite3requiredPeer dependency providing the underlying synchronous SQLite3 bindings.
Agent activity
16 hits · last 30 days
node
12
Meta
1
Amazon
1
OpenAI (training)
1
Resources
sqlite-async — npm install sqlite-async · libregistry