Registry / database / functional-models-orm

functional-models-orm

JSON →
library2.1.14jsnpmunverified

A functional ORM building library for functional-models, providing a standardized way to create database-backed models using functional paradigms. Current stable version is 2.1.14, released periodically. Key differentiators: uses a BaseModel that can be swapped with any functional-models BaseModel, supports multiple datastore providers (DynamoDB, MongoDB/DocumentDB), and provides common query operations (save, delete, retrieve, search) with automatic serialization and nested model references. Designed for no state changes.

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

orm
import { orm } from 'functional-models-orm'
import orm from 'functional-models-orm'
Default export is not available; use named import. This is ESM-compatible.
BaseModel
const myOrm = orm({ datastoreProvider }); const BaseModel = myOrm.BaseModel
import { BaseModel } from 'functional-models-orm'
BaseModel is not exported directly; it's obtained from the orm instance. Version 2.x changed this API.
types
import type { DatastoreProvider, OrmInstance } from 'functional-models-orm'
TypeScript types are provided; import types for DatastoreProvider and OrmInstance.

Quickstart creating an ORM instance, defining a model, saving it, and logging the result.

import { orm } from 'functional-models-orm'; import { UniqueId, TextProperty } from 'functional-models'; // Assume a datastoreProvider is configured (e.g., from 'functional-models-orm-dynamo') const myOrm = orm({ datastoreProvider: process.env.DATASTORE_PROVIDER ?? 'memory' }); const Trains = myOrm.BaseModel('Trains', { name: TextProperty() }); async function run() { const modelInstance = Trains.create({ name: 'Yellow Train' }); const savedModel = await modelInstance.save(); console.log(await savedModel.toObj()); } run();
Debug
Known issues
breakingBaseModel is no longer a direct export; it must be obtained from the orm instance after calling orm()
fix
Use `const myOrm = orm({ datastoreProvider }); const BaseModel = myOrm.BaseModel`
affects: >=2.0.0
deprecatedThe `bulkInsert` method default implementation uses in-memory logic; may not be performant for large datasets
fix
Override `bulkInsert` in your DatastoreProvider for database-specific behavior
affects: >=1.0.0
gotchaProperty 'id' is automatically added by BaseModel; do not define it manually
fix
Remove 'id' from model definitions
affects: >=1.0.0
gotchaUpdate operation is same as create; no separate update method exists
fix
Use save (create) to overwrite existing records
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'BaseModel')
BaseModel is not exported directly; it's a property of the orm instance
fix
import { orm } from 'functional-models-orm'; const myOrm = orm({ datastoreProvider }); const BaseModel = myOrm.BaseModel
Error: datastoreProvider is required
Missing datastoreProvider configuration in orm() call
fix
Ensure you pass a valid datastoreProvider object to orm()
Upgrade
Version history
2.1.14latest on npm
Audit
Dependencies
functional-modelsrequiredCore library providing the BaseModel and property types; ORM builds on top of functional-models
Agent activity
5 hits · last 30 days
node
4
Resources
functional-models-orm — npm install functional-models-orm · libregistry