Registry / database / minidb

minidb

JSON →
library0.16.0jsnpmunverified

A minimal ORM for PostgreSQL and SQLite, version 0.16.0. It provides a low-level wrapper with a focus on simplicity and transparency, avoiding automatic migrations, relationships, or identity management. Suitable for small projects and developers who prefer explicit database control.

npm install minidb
INSTALL
IMPORT
SIG · MINIDB
M
minidb
databasejavascriptv0.16.0
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.

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);
Debug
Known issues
breakingIn version 0.15.0, the import path changed to named exports; require() no longer works.
fix
Use import { PersistentObject, SQLite } from 'minidb' instead of const Minidb = require('minidb').
affects: >=0.15.0
gotchaPersistentObject.register() must be called for each subclass before any database operations.
fix
Ensure you call PersistentObject.register(YourClass) right after class definition.
affects: >=0.0.0
gotchaThe SQLite driver (sqlite3) must be installed separately; it's a peer dependency.
fix
Run npm install sqlite3 if you plan to use SQLite.
affects: >=0.0.0
gotchaThe Postgres driver (pg) must be installed separately; it's a peer dependency.
fix
Run npm install pg if you plan to use PostgreSQL.
affects: >=0.0.0
deprecatedThe method 'findAll' was deprecated in 0.12.0; use 'find' with query criteria instead.
fix
Replace User.findAll() with User.find(db, {}).
affects: >=0.12.0
Errors
Common errors & fixes
TypeError: PersistentObject is not a constructor
Using require() in an ESM-only environment or mixing import/require styles.
fix
Use import { PersistentObject } from 'minidb' and ensure Node.js version supports ESM.
Error: Cannot find module 'sqlite3'
The optional peer dependency sqlite3 is not installed.
fix
Install sqlite3: npm install sqlite3
Error: Cannot find module 'pg'
The optional peer dependency pg is not installed.
fix
Install pg: npm install pg
AssertionError [ERR_ASSERTION]: tableName must be defined
Forgetting to define static get tableName() in the subclass.
fix
Add 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.
fix
Call await db.open() after constructing the database object.
Upgrade
Version history
0.16.0latest on npm
Audit
Dependencies
pgoptionalPostgreSQL driver
sqlite3optionalSQLite driver
Agent activity
4 hits · last 30 days
node
4
Resources
packageminidb
minidb — npm install minidb · libregistry