Registry / database / forj
library0.1.11jsnpmunverified

Forj is a lightweight, dependency-free SQLite ORM and Query Builder for Node.js 18+. Version 0.1.11 supports schema migrations, query building, and an active record-like ORM pattern. Unlike heavier ORMs like Sequelize or Knex, Forj has zero dependencies and focuses on SQLite exclusively, making it ideal for embedded databases and serverless environments. It provides both a fluent query builder and a resource-based ORM with support for transactions, migrations, and model definitions. The package is released under the MIT license and follows semantic versioning.

npm install forj
INSTALL
IMPORT
SIG · FORJ
F
forj
databasejavascriptv0.1.11
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.

Forj
✓ import Forj from 'forj'
✗ const Forj = require('forj')
ESM-only since v0.1.0; no CommonJS support.
Schema
✓ import { Schema } from 'forj'
✗ const Schema = require('forj').Schema
Named export; available in ESM only.
Model
✓ import { Model } from 'forj'
✗ const { Model } = require('forj')
Named export for ORM model definitions.
Resource
✓ import { Resource } from 'forj'
Resource class for building CRUD APIs.

Demonstrates initializing Forj, defining a schema, creating a model, inserting a record, and querying with the builder.

import Forj, { Schema, Model } from 'forj'; // Initialize Forj with a database file const forj = new Forj({ path: ':memory:', logging: false }); // Define a schema const userSchema = new Schema('users', { id: { type: 'integer', primary: true, autoIncrement: true }, name: { type: 'text', notNull: true }, email: { type: 'text', unique: true }, age: { type: 'integer', default: 0 } }); // Create the table (run once) await forj.run(userSchema.create()); // Define a model class User extends Model { static get schema() { return userSchema; } } // Insert a record const user = new User({ name: 'Alice', email: 'alice@example.com', age: 30 }); await user.save(); // Query using the query builder const users = await forj.table('users').where('age', '>', 18).all(); console.log(users); // Close connection await forj.close();
Debug
Known issues
breakingForj requires Node.js >= 18.0.0 due to ESM support and native APIs.
fix
Upgrade Node.js to version 18 or later.
affects: >=0.1.0
deprecatedThe `Forj.prototype.table()` method is deprecated since v0.1.10; use `Forj.prototype.query()` instead.
fix
Replace `forj.table('name')` with `forj.query('name')`.
affects: >=0.1.10 <0.2.0
gotchaSchema column type 'integer' is used for autoIncrement; using 'int' may cause unexpected behavior.
fix
Use only 'integer', 'text', 'real', 'blob', or 'numeric' as column types.
affects: >=0.1.0
breakingModel.save() returns undefined in v0.1.11; previous versions returned the inserted row.
fix
Check for successful save by catching errors or using Model.create() which returns the row.
affects: =0.1.11
deprecatedThe `Schema` constructor's third parameter (options) is deprecated; pass options as part of the column definition.
fix
Move options like `autoIncrement: true` into the column definition object.
affects: >=0.1.5
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using CommonJS require() to import an ESM-only package.
fix
Use `import` syntax or switch to dynamic import: `const Forj = (await import('forj')).default`.
TypeError: forj.table is not a function
Calling deprecated `table()` method after v0.1.10.
fix
Use `forj.query('tableName')` instead.
SQLITE_ERROR: table users already exists
Running schema.create() multiple times without checking for existing table.
fix
Use `schema.create({ ifNotExists: true })` or wrap in a try-catch.
ForjError: Column type 'string' is not a valid SQLite type.
Using JavaScript types like 'string' instead of SQLite types.
fix
Change column type to 'text' (or 'integer', 'real', 'blob', 'numeric').
Upgrade
Version history
0.1.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources
packageforj ↗
forj — npm install forj · libregistry