Registry / database / like-sqlite

like-sqlite

JSON →
library1.0.2jsnpmunverified

like-sqlite v1.0.2 is a lightweight, promise-based SQLite wrapper for Node.js that simplifies common CRUD operations (insert, select, update, delete) with automatic query construction and parameter binding. It wraps better-sqlite3, providing an intuitive API with methods like insert(), select(), update(), delete(), execute(), and query(). Released under MIT, it receives active development on GitHub. Key differentiators: no raw SQL needed for basic operations, built-in support for upserts and expressions, and full async/await support.

npm install like-sqlite
INSTALL
IMPORT
SIG · LIKE-SQLITE
L
like-sqlite
databasejavascriptv1.0.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.

default export
const SQLite = require('like-sqlite')
import SQLite from 'like-sqlite'
CommonJS-only; no ESM export available.
SQLite instance
const db = new SQLite('./database.db')
const db = new SQLite({ filename: './database.db' })
Constructor expects filename string as first argument, not an options object.
insert method
const id = await db.insert('ips', { addr: '127.0.0.1', hits: 0 })
const id = await db.insert('INSERT INTO ips (addr, hits) VALUES (?, ?)', ['127.0.0.1', 0])
insert() takes table name and object, not raw SQL.

Demonstrates all common CRUD operations: table creation, insert, select, selectOne, update, exists, count, delete with parameterized queries.

const SQLite = require('like-sqlite'); async function main() { const db = new SQLite('./test.db', { journal: 'WAL' }); // Create a table await db.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT)'); // Insert a user const id = await db.insert('users', { name: 'Alice', email: 'alice@example.com' }); console.log('Inserted user with id:', id); // Select all users const rows = await db.select('users', ['id', 'name', 'email']); console.log('All users:', rows); // Select one user const user = await db.selectOne('users', ['id', 'name', 'email'], 'id = ?', id); console.log('User by id:', user); // Update user await db.update('users', { email: 'alice@newdomain.com' }, 'id = ?', id); // Check existence const exists = await db.exists('users', 'id = ?', id); console.log('User exists:', exists); // Count users const count = await db.count('users'); console.log('Total users:', count); // Delete user await db.delete('users', 'id = ?', id); db.close(); } main().catch(console.error);
Debug
Known issues
gotchaConstructor must be called with `new`; without it, a TypeError is thrown.
fix
Always use `new SQLite(...)`
affects: >=1.0
breakingNo ESM or CJS named exports; only a default CommonJS export is provided.
fix
Use `const SQLite = require('like-sqlite')` instead of `import`.
affects: >=1.0
gotchaUsing invalid or empty column names in `select`/`selectOne` will cause runtime SQL errors.
fix
Always use valid column names from the table schema.
affects: >=1.0
deprecatedThe `options.nativeBinding` option is deprecated and may be removed in a future version.
fix
Use `options.nativeBinding` only if you have a custom better-sqlite3 build.
affects: >=1.0
Errors
Common errors & fixes
TypeError: Class constructor SQLite cannot be invoked without 'new'
Missing `new` keyword when creating SQLite instance.
fix
const db = new SQLite('./database.db')
Error: SQLITE_ERROR: no such table: users
Table `users` does not exist before performing CRUD operations.
fix
Create the table first using `db.execute('CREATE TABLE users (...)' )`
Error: SQLITE_ERROR: near "?": syntax error
Using question marks in raw SQL without corresponding parameter array.
fix
Pass parameters as an array: `[req.ip]` in `execute()` or `query()`.
TypeError: db.insert is not a function
Using older version or incorrect import (e.g., ESM import).
fix
Use `require('like-sqlite')` and ensure version >=1.0.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
better-sqlite3requiredRuntime dependency for SQLite database engine
Agent activity
10 hits · last 30 days
node
6
Resources
like-sqlite — npm install like-sqlite · libregistry