Registry / database / memory-orm

memory-orm

JSON →
library0.7.0jsnpmunverified

An in-memory client-side ORM with map-reduce capabilities for JavaScript, version 0.7.0 (appears stable, low release cadence). It allows defining schemas with associations (has_many, belongs_to), querying data via Set and Query objects, and performing map-reduce aggregations (count, avg, min, max, variance, etc.). Differentiators: built-in map-reduce engine for client-side data analysis, schema-based relationships, and ordering/filtering operators. Works in Node.js and browser. Ships TypeScript types. Not to be confused with server-side ORMs like Sequelize or TypeORM.

npm install memory-orm
INSTALL
IMPORT
SIG · MEMORY-ORM
M
memory-orm
databasejavascriptv0.7.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.

Rule
import { Rule } from 'memory-orm'
const Rule = require('memory-orm').Rule
ESM import for named export; also works with CJS require.
Set
import { Set } from 'memory-orm'
const Set = require('memory-orm').Set
Set is a named export, not default. Avoid conflicts with ES Set global.
Query
import { Query } from 'memory-orm'
import Query from 'memory-orm'
Query is a named export, not default.

Define schemas with associations, insert data, and query with pluck and relationship traversal.

import { Rule, Set, Query } from 'memory-orm'; new Rule('todo').schema(function () { this.has_many('checks'); }); new Rule('check').schema(function () { this.belongs_to('todo'); }); Set.todo.merge([ { _id: 1, label: '歯を磨く' }, { _id: 2, label: '宿題をする' }, { _id: 3, label: 'お風呂はいる' }, ]); Set.check.merge([ { _id: 1, todo_id: 1, label: '右上', checked: true }, { _id: 2, todo_id: 1, label: '左上', checked: true }, { _id: 3, todo_id: 3, label: 'シャワー浴びる', checked: false }, { _id: 4, todo_id: 3, label: '肩まで入って10数える', checked: true }, ]); console.log(Query.todos.pluck('label')); // ['歯を磨く', '宿題をする', 'お風呂はいる'] console.log(Query.todos.find(3).checks.where({ checked: true }).list); // [{_id:4, ...}] console.log(Query.todos.find(3).checks.where({ checked: false }).list); // [{_id:3, ...}]
Debug
Known issues
gotchaSet and Query are global singletons; all rules must be registered before data insertion or queries.
fix
Always define rules first using new Rule(), then use Set.merge() and Query.
affects: >=0.0.0
gotchaThe Set object conflicts with the JavaScript built-in Set; avoid using both in the same scope without aliasing.
fix
Import Set as { Set as MemorySet } from 'memory-orm' if needed alongside native Set.
affects: >=0.0.0
breakingAPI changed between versions: earlier versions used Setup.set() vs now Set.merge().
fix
Upgrade to >=0.5.0 and use Set.merge() for inserting data.
affects: <0.5.0
Errors
Common errors & fixes
Uncaught TypeError: Set.todo is undefined
Rule for 'todo' not registered before using Set.todo.
fix
Add new Rule('todo').schema(...) before Set.todo.merge(...).
TypeError: (intermediate value).checks is undefined
Query.find() returns undefined if no document matches the _id.
fix
Ensure the document exists with that _id before accessing relationships.
Error: Rule 'check' already exists
Duplicating a rule definition for the same entity name.
fix
Remove duplicate new Rule('check') or check if rule already exists programmatically.
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies
lodashoptionalUsed for orderBy and other utilities (indirect dependency via peer dependency in older versions, but not explicitly listed, likely bundled or internal)
Agent activity
4 hits · last 30 days
node
4
Resources
memory-orm — npm install memory-orm · libregistry