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);
Errors
Common errors & fixes
TypeError: Class constructor SQLite cannot be invoked without 'new'
Missing `new` keyword when creating SQLite instance.
fixconst db = new SQLite('./database.db') Error: SQLITE_ERROR: no such table: users
Table `users` does not exist before performing CRUD operations.
fixCreate 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.
fixPass 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).
fixUse `require('like-sqlite')` and ensure version >=1.0. Audit
Dependencies
better-sqlite3requiredRuntime dependency for SQLite database engine