Redux Database is a JavaScript library providing an in-memory, reducer-based relational database for client-side state management. It allows developers to organize application state in a structured, relational manner, similar to an SQL database, complete with queries and joins. The library ships with strong TypeScript typings, ensuring type safety for schema definitions, queries, and data manipulation. It supports immutable documents and offers plugins for seamless integration with Redux stores or can be used standalone, notably having no direct dependencies itself. Currently at version 0.0.20, its release cadence appears to be incremental, focusing on feature development and refinement rather than rapid major version changes. A key differentiator is its focus on client-side data normalization, offering a chainable query syntax, embedded relations for joins, and transaction support to optimize state updates and prevent performance issues from excessive dispatches. It aims to simplify complex client-side data challenges by providing a structured, queryable layer over the Redux state.
npm install redux-databaseVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining a database schema, initializing a Redux store with the database reducer, performing transactional writes, and executing chainable queries including embedded relations.
Always wrap multiple write operations within a transaction using `db.transaction((dispatch) => { ... })` to ensure a single Redux action is dispatched for all changes, optimizing performance.Always use the provided write methods (e.g., `db.table('items').insert()`, `update()`, `delete()`, `db.set()`) on `DB` or table instances. These methods return Redux actions that must be dispatched to correctly update the immutable state.After any state update that affects the database slice of your Redux store, create a new `DB` instance from the updated store state: `db = new DB(store.getState().db);`.
Ensure your database schema (`interface State`) correctly defines all tables under the `data` key and settings under the `settings` key before attempting to access them via `db.table('xyz')` or `db.get('xyz')`.Ensure that any object passed to `insert()` or `update()` methods strictly conforms to the TypeScript interface defined for that table's model, including all required properties like `id`.
No dependency data recorded yet.