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.
PersistentObject
✓ import { PersistentObject } from 'minidb'
✗ const PersistentObject = require('minidb').PersistentObject
ESM-only; CommonJS require may not work if package is ESM-only.
SQLite
✓ import { SQLite } from 'minidb'
✗ import SQLite from 'minidb'
Default import not available; must use named import.
Postgres
✓ import { Postgres } from 'minidb'
✗ import { Postgres } from 'minidb/pg'
Postgres is exported from the main module, not a subpath.
Shows how to define a model, open SQLite database, create table, and insert/find a record.
import { PersistentObject, SQLite } from 'minidb';
class User extends PersistentObject {
static get tableName() { return 'users'; }
static get columns() {
return [
{ name: 'name', column: 'name', type: 'string', null: false },
{ name: 'email', column: 'email', type: 'string', null: false },
{ name: 'age', column: 'age', type: 'integer', null: false },
{ name: 'height', column: 'height', type: 'double' },
{ name: 'birthDate', column: 'birth_date', type: 'date' }
];
}
}
PersistentObject.register(User);
const db = new SQLite({ file: 'users.db' });
await db.open();
await db.execute(`
CREATE TABLE IF NOT EXISTS users (
id bigserial NOT NULL,
name text NOT NULL,
email text NOT NULL,
age bigint NOT NULL,
height double precision,
birth_date date,
created_at double precision,
updated_at double precision
);
`);
const user = await User.findOrCreate(db, { name: 'John', email: 'john@example.com', age: 30 });
user.height = 72.3;
await user.save();
console.log('User created:', user.id);
Errors
Common errors & fixes
TypeError: PersistentObject is not a constructor
Using require() in an ESM-only environment or mixing import/require styles.
fixUse import { PersistentObject } from 'minidb' and ensure Node.js version supports ESM. Error: Cannot find module 'sqlite3'
The optional peer dependency sqlite3 is not installed.
fixInstall sqlite3: npm install sqlite3
Error: Cannot find module 'pg'
The optional peer dependency pg is not installed.
fixInstall pg: npm install pg
AssertionError [ERR_ASSERTION]: tableName must be defined
Forgetting to define static get tableName() in the subclass.
fixAdd static get tableName() { return 'your_table_name'; } to your class. TypeError: db.open is not a function
The database instance must be opened with await db.open() before operations.
fixCall await db.open() after constructing the database object.
Audit
Dependencies
pgoptionalPostgreSQL driver
sqlite3optionalSQLite driver