Registry / database / json-db-orm

json-db-orm

JSON →
library0.2.14jsnpmunverified

A simple ORM wrapper for node-json-db, providing decorator-based schema definitions, validators, auto-increment primary keys, and default values. Current version 0.2.14. Release cadence is irregular, with limited recent updates. Key differentiators: lightweight, uses decorators for TypeScript, integrates tightly with node-json-db, and includes built-in validation and default value support.

npm install json-db-orm
INSTALL
IMPORT
SIG · JSON-DB-ORM
J
json-db-orm
databasejavascriptv0.2.14
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.

Store
import { Store } from 'json-db-orm'
const Store = require('json-db-orm').Store
ESM module, named export.
Schema
import { Schema } from 'json-db-orm'
import { Schema } from 'json-db-orm/dist'
Decorator for class schemas.
Field
import { Field } from 'json-db-orm'
import { Field } from 'json-db-orm/Field'
Used as property decorator.
ListSchema
import { ListSchema } from 'json-db-orm'
import { ListSchema } from 'json-db-orm/schemas'
Base class for array-based schemas.
KeySchema
import { KeySchema } from 'json-db-orm'
Base class for key-value schemas.

Demonstrates schema definition, auto-increment primary key, field validation, default value, and saving a record.

import { Store, Schema, Field, AutoIncrementPrimary, ListSchema } from 'json-db-orm'; import * as path from 'path'; Store.root = path.resolve(__dirname, 'data'); @Schema('records') class Record extends ListSchema { @AutoIncrementPrimary() id: number; @Field({ validate: (v: string) => v.length <= 140 }) message: string; @Field({ default: () => new Date().toISOString() }) timestamp: string; } const record = new Record(); record.message = 'Hello, world!'; record.save().then(() => console.log('Saved')).catch(console.error);
Debug
Known issues
gotchareflect-metadata must be imported once at the top of your entry file
fix
Add import 'reflect-metadata' at the top of your entry file.
affects: >=0.0.0
gotchaStore.root must be set before any schema methods are called
fix
Set Store.root immediately after imports, before any class instantiation.
affects: >=0.0.0
deprecatedThe package has not been updated in over 2 years; use with caution in new projects
fix
Consider migrating to a more actively maintained library.
affects: >=0.2.0
gotchaAutoIncrementPrimary only works with ListSchema, not KeySchema
fix
Use @Primary() decorator for KeySchema classes.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'node-json-db'
node-json-db is a peer dependency that must be installed separately
fix
npm install node-json-db
TypeError: Store.root is not set
Store.root was not assigned before saving
fix
Add Store.root = 'path/to/data' before any save() calls.
Reflect.getMetadata is not a function
reflect-metadata is not imported
fix
Add import 'reflect-metadata' at the top of your entry file.
Upgrade
Version history
0.2.14latest on npm
Audit
Dependencies
node-json-dbrequiredcore database engine
reflect-metadatarequiredrequired for decorators in TypeScript
Agent activity
6 hits · last 30 days
node
6
Resources
json-db-orm — npm install json-db-orm · libregistry