The state type of your database schema.
Create a snapshot from the given state. Can either be used in conjunction with redux or implicitly
by calling mutableDB.snapshot
.
Commit changes in a context to its parent. You can either commit individual ids, full tables or the whole context.
Access a named context.
const draftDB = db.context('draft');
store.dispatch(draftDB.table('things').update('1', { name: 'Updated Thing' }));
// retrieve your state again from the store
db.table('things').first.name; // this is still 'First Thing'
draftDB.table('things').first.name; // this is updated to 'Updated Thing'
Revert changes in a context. You can either revert individual ids, full tables or the whole context.
Get the value from the key-value store.
A key of your key-value schema
the value of the supplied key, undefined
if no value is set yet
Set a value in your key-value storage. This action does not mutate your state but returns an action to be dispatched.
The key to update.
The value to set for this key.
Send this value to your dispatch function.
Resets the given type back to the initial state. If you want to have empty tables, use truncate instead.
all
: Reset settings and tables back to initial state.tables
: Reset tables, but keeps current settings.settings
: Reset settings, but keeps all tables.Truncates all tables. After this action, all tables are empty. This will not change settings. If you would like to reset settings instead, use reset.
Start a composable query. Queries allow chaining together different queries, joins and transformations.
const things = db.query('things').where({name: 'tool'}).embed('user', 'users', 'userId).order({name: 'desc'}).all;
Name of the table to start the query on.
Start a transaction to group updates. This is mostly used to prevent rerenders if you're planning to update multiple values and tables.
store.dispatch(
db.transaction(dispatch => {
dispatch(things.insert({ name: 'First Thing' }));
dispatch(things.insert({ name: 'Second Thing' }));
})
);
Your execution function
The action that you should send to your reducer.
Generated using TypeDoc
DB
is a snapshot of your current database state. It helps you reading data viaget
,table
andquery
.const db = new DB(state); db.get('enableAwesomeThing'); // true const things = db.table('things'); // if things is not defined, you would get an error here things.all; // returns Thing[] things.find('12'); // find by id things.where({ name: 'tool' }); // simple equality based where queries things.where(thing => thing.name.length == 4); // function based where queries