Registry / database / redux-orm-kerad

redux-orm-kerad

JSON →
library1.0.3jsnpmunverified

A small, simple and immutable ORM to manage relational data in your Redux store. It provides a way to define models with relationships (foreign keys, one-to-one, many-to-many) and query them using a familiar ORM-like API. The library integrates with Redux by generating reducers that manage entity state. Current stable version is 1.0.3, released occasionally with bug fixes. Key differentiators: minimalistic design, immutable state, and seamless Redux integration.

npm install redux-orm-kerad
INSTALL
IMPORT
SIG · REDUX-ORM-KERAD
R
redux-orm-kerad
databasejavascriptv1.0.3
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 'redux-orm'
✗ const ORM = require('redux-orm')
If using CommonJS, use require('redux-orm').ORM
Model
✓ import { Model, attr, fk, oneToOne, many } from 'redux-orm'
✗ import { Model, attributes, foreignKey } from 'redux-orm'
Field types are attr, fk, oneToOne, many
createReducer
✓ import { createReducer } from 'redux-orm'
✗ import { reducer } from 'redux-orm'
Function to create a reducer from ORM instance

Defines an Author model, registers it with ORM, creates a Redux reducer, and demonstrates basic creation/query.

// models.js import { Model, attr, fk, many } from 'redux-orm'; class Author extends Model { toString() { return `Author: ${this.name}`; } } Author.modelName = 'Author'; Author.fields = { id: attr(), name: attr(), books: many('Book', 'authors') }; export default Author; // orm.js import { ORM } from 'redux-orm'; import Author from './models'; const orm = new ORM(); orm.register(Author); // register all models export default orm; // store.js import { createStore, combineReducers } from 'redux'; import { createReducer } from 'redux-orm'; import orm from './orm'; const reducer = createReducer(orm); const rootReducer = combineReducers({ orm: reducer }); const store = createStore(rootReducer); // usage: const session = orm.session(store.getState().orm); const author = session.Author.create({ name: 'John' }); console.log(author.name); // John
Debug
Known issues
breakingVersion 0.9 introduced breaking changes to the API. The migration guide is available.
fix
Follow the 0.9 migration guide: https://github.com/tommikaikkonen/redux-orm/wiki/0.9-Migration-Guide
affects: >=0.9 <1.0.0
deprecatedThe 'models' getter on ORM instances is deprecated in favor of direct method calls.
fix
Use orm.session(state) instead of orm.models
affects: >=0.9
gotchaField types must be assigned to the static 'fields' property on Model classes, not in constructor.
fix
Declare fields as static property: Book.fields = { ... }
affects: *
Errors
Common errors & fixes
TypeError: Cannot read property 'session' of undefined
ORM instance not created or not imported correctly
fix
Ensure you have imported and instantiated ORM: import { ORM } from 'redux-orm'; const orm = new ORM();
Uncaught Error: Model "Book" is not registered.
Forgot to register the model with the ORM instance
fix
Call orm.register(Book) before using the model.
Error: createReducer expects a valid ORM instance
Passed an unregistered ORM instance or wrong object
fix
Ensure you pass the ORM instance that has registered models: createReducer(orm)
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
reduxrequiredredux-orm is designed to work with Redux store
Agent activity
25 hits · last 30 days
node
20
OpenAI (training)
1
Resources
redux-orm-kerad — npm install redux-orm-kerad · libregistry