Registry / database / functional-models-orm-json

functional-models-orm-json

JSON →
library3.0.2jsnpmunverified

An ORM adapter for functional-models that stores data in JSON files. Current version 3.0.2. This package implements the datastoreAdapter interface from functional-models, allowing you to use a JSON file as a database backend. It is designed for small-scale, file-based persistence, often used in prototyping, local development, or low-traffic applications. Unlike SQLite or LevelDB, it stores the entire dataset in a single JSON file, which is simple to inspect and version-control. Release cadence is irregular as it is part of the functional-models ecosystem.

npm install functional-models-orm-json
INSTALL
IMPORT
SIG · FUNCTIONAL-MODELS-
F
functional-models-orm-json
databasejavascriptv3.0.2
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.

datastoreAdapter
import { datastoreAdapter } from 'functional-models-orm-json'
const datastoreAdapter = require('functional-models-orm-json')
Named ESM export. CommonJS require returns the module object; you must destructure or use .datastoreAdapter.
datastoreAdapter
const { datastoreAdapter } = require('functional-models-orm-json')
const datastoreAdapter = require('functional-models-orm-json').default
CommonJS named export via destructuring. No default export.

Shows how to set up the ORM with a JSON file, define a model, and create/save a record.

const { jsonClient } = require('jsondb'); const { createOrm } = require('functional-models'); const { datastoreAdapter } = require('functional-models-orm-json'); const filePath = './data.json'; const adapter = datastoreAdapter({ filePath }); const orm = createOrm({ datastoreAdapter: adapter }); const User = orm.defineModel({ name: 'user', attributes: { id: { type: 'string', required: true }, name: { type: 'string', required: true }, email: { type: 'string' }, }, }); const user = User.create({ id: '1', name: 'Alice', email: 'alice@example.com' }); user.save().then(() => console.log('User saved'));
Debug
Known issues
gotchaJSON file must exist and be a valid JSON array. If file is empty or missing, adapter fails.
fix
Initialize the JSON file with an empty array ([]) if it does not exist.
affects: >=2.0.0
gotchaAll data is loaded into memory on startup. Large files may cause performance issues.
fix
Use only for small datasets, or consider an alternative backend like SQLite.
affects: >=1.0.0
gotchaNo concurrent write support; multiple writes can corrupt the file.
fix
Ensure single-process access or use file locking.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'functional-models-orm-json'
Package not installed or not properly required.
fix
Run npm install functional-models-orm-json and ensure correct import path.
TypeError: datastoreAdapter is not a function
Importing the module incorrectly (e.g., as default instead of named).
fix
Use const { datastoreAdapter } = require('functional-models-orm-json');
Error: ENOENT: no such file or directory, open './data.json'
The JSON file path provided to datastoreAdapter does not exist.
fix
Create the file or adjust the path; ensure the file contains a valid JSON array.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies
functional-modelsrequiredPeer dependency; provides the core ORM framework and datastoreAdapter interface.
jsondbrequiredProvides the underlying JSON file client for reading/writing the JSON database.
Agent activity
6 hits · last 30 days
node
4
Resources
functional-models-orm-json — npm install functional-models-orm-json · libregistry