Registry / database / sqlite3orm

sqlite3orm

JSON →
library3.0.0jsnpmunverified

ORM library for SQLite3 in TypeScript/JavaScript (v3.0.0). Uses ES decorators (@table, @id, @field) to map classes to database tables with automatic schema creation, connection pooling, and online backups. Provides type-safe queries with a filter syntax that eliminates SQL injection risks. Released under MIT, maintained with regular updates. Key differentiator: full control over schema naming, support for temporary tables, and partial model mapping. Also offers automatic upgrades and integration with NestJS via companion package @homeofthings/nestjs-sqlite3.

npm install sqlite3orm
INSTALL
IMPORT
SIG · SQLITE3ORM
S
sqlite3orm
databasejavascriptv3.0.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.

SqlDatabase
import { SqlDatabase } from 'sqlite3orm';
const SqlDatabase = require('sqlite3orm').SqlDatabase;
ESM default; CommonJS require is possible but not recommended.
schema
import { schema } from 'sqlite3orm';
import schema from 'sqlite3orm';
Named export, not default export. Use destructured import.
@table
import { table } from 'sqlite3orm';
import { Table } from 'sqlite3orm';
The decorator is exported as a lowercase 'table'. Also exports @field, @id, @fk, @index similarly.

Define a User model class with decorators, create an in-memory database, create the schema, insert a record, and query all rows.

import { SqlDatabase, schema, table, id, field } from 'sqlite3orm'; @table({ name: 'users' }) class User { @id({ name: 'id', dbtype: 'INTEGER NOT NULL' }) userId!: number; @field({ name: 'name', dbtype: 'TEXT NOT NULL' }) name!: string; } const db = new SqlDatabase(); await db.open(':memory:'); await schema(db, [User]); const stmt = db.prepare('INSERT INTO users (name) VALUES (?)'); stmt.run('Alice'); const rows = db.prepare('SELECT * FROM users').all(); console.log(rows); await db.close();
Debug
Known issues
breakingVersion 3.0.0 drops support for Node.js < 14 and requires TypeScript >= 4.0 for decorator support.
fix
Update Node.js to v14+ and TypeScript to v4+.
affects: >=3.0.0
gotchaProperties without a decorator (@field, @id, etc.) will NOT be mapped to the database.
fix
Ensure all database columns are annotated with the appropriate decorator.
affects: *
gotchaThe @table decorator must be applied to classes with @id fields. Omitting @id will cause schema creation to fail.
fix
Always include at least one @id-decorated field in every @table class.
affects: *
deprecatedThe 'temp' table qualifier in @table name (e.g., 'temp.MYTEMPTABLE') is deprecated and will be removed in v4.
fix
Use separate temporary table management instead of prefixing table names with 'temp.'
affects: 3.x
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Missing import of reflect-metadata or incorrect decorator import.
fix
Add 'import "reflect-metadata";' at the top of your entry file.
Cannot find module 'sqlite3orm' or its corresponding type declarations.
Package not installed or TypeScript cannot resolve types.
fix
Run 'npm install sqlite3orm' and ensure tsconfig.json includes 'node_modules/@types'.
SQLITE_ERROR: no such table: users
Schema was not created before querying.
fix
Call 'await schema(db, [User]);' before executing any SQL against the table.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
better-sqlite3requiredSQLite3 driver for Node.js
reflect-metadatarequiredRequired for decorator metadata reflection
Agent activity
14 hits · last 30 days
node
10
Meta
2
OpenAI (training)
1
Resources
sqlite3orm — npm install sqlite3orm · libregistry