Registry / database / sync-sqlite

sync-sqlite

JSON →
library1.0.3jsnpmunverified

Synchronous SQLite library for Node.js built on sql.js. Version 1.0.3 provides a simple synchronous API for common database operations (create, read, update, delete) with automatic save and pagination. Unlike async alternatives like better-sqlite3, it offers a CRUD helper layer (select, insert, update, remove) that returns RecordSet objects. Designed for simplicity, it exposes methods like runSQL and execute for raw SQL. The package is stable but rarely updated, suitable for small projects needing synchronous SQLite access.

npm install sync-sqlite
INSTALL
IMPORT
SIG · SYNC-SQLITE
S
sync-sqlite
databasejavascriptv1.0.3
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.

default
const SQLite = require('sync-sqlite');
import SQLite from 'sync-sqlite';
CJS-only module; no ESM export.
new SQLite(options)
const db = new SQLite({ dbPath: './test.db', autoSave: true });
const db = new SQLite();
Options object with at least dbPath is required.
RecordSet
// RecordSet is returned from methods, not imported separately
const { RecordSet } = require('sync-sqlite');
RecordSet is an internal class; not directly importable.

Demonstrates creating a table, inserting data, selecting, updating, and deleting rows synchronously.

const SQLite = require('sync-sqlite'); const db = new SQLite({ dbPath: './test.db', autoSave: true }); db.createTable('users', ['id INTEGER PRIMARY KEY', 'name TEXT', 'email TEXT']); const result = db.insert('users', { name: 'Alice', email: 'alice@example.com' }); console.log(`Inserted row ID: ${result.id}`); const rows = db.select('users', '*', ''); console.log(rows.toJSON()); const updateResult = db.update('users', { email: 'alice@newdomain.com' }, 'id=1'); console.log(`Updated ${updateResult.ar} rows`); const deleteResult = db.remove('users', '*', 'id=1'); console.log(`Deleted ${deleteResult.ar} rows`);
Debug
Known issues
gotchaSynchronous API blocks the event loop; do not use in production servers with high concurrency.
fix
Use async libraries like better-sqlite3 with worker threads or consider sql.js async methods.
affects: all
gotchaThe module uses sql.js which loads a WASM binary; path issues may arise in bundled or restricted environments.
fix
Ensure WASM file is accessible; set SQL_JS_WASM_LOCATION if needed.
affects: all
gotchaAll methods expect plain strings for SQL conditions; no parameterized queries — risk of SQL injection if user input is concatenated.
fix
Use escape methods or switch to a library with prepared statements.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'sql.js'
sql.js is a peer dependency not automatically installed.
fix
Run: npm install sql.js
TypeError: db.select is not a function
Trying to call methods before calling connect() or using wrong import.
fix
Ensure typeof db === 'object' and db.table() is called if table name not passed in method.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
sql.jsrequiredSQLite WebAssembly engine for in-memory databases
Agent activity
19 hits · last 30 days
node
14
Meta
2
Amazon
1
OpenAI (training)
1
Resources
sync-sqlite — npm install sync-sqlite · libregistry