1.0.1-alpha.4 • Published 1 year ago
@tabular-state/database v1.0.1-alpha.4
@tabular-state/database
A database adapter for @tabular-state/store to persist state in IndexedDB.
Warning Persisting state is currently only supported in browsers with indexeddb support.
import { createStore } from '@tabular-state/store';
const store = createStore<Tables>();
Using IndexedDB
Uses idb-keyval under the hood.
npm install @tabular-state/database idb-keyval
pnpm install @tabular-state/database idb-keyval
yarn add @tabular-state/database idb-keyval
import { createIndexedDbAdapter } from '@tabular-state/database';
const database = ceateIndexedDbAdapter({
autoPersistTables: [['users', 'id']],
checkAutoPersistTables(tableName) {
if (tableName === 'any-dynamic-database') {
return 'customIdField';
}
return false;
},
onRevalidate(table, ids) {
// do something when persisted state has been revalidated
},
});
// or with specific namespace
const database = ceateIndexedDbAdapter({
namespace: 'account-1',
// ...
});
store.plugin(database);
Namespaces
It is possible to implement splitted databases by switching the database namespace. A possible use case is an application where the user can switch between multiple accounts and or workspaces.
database.setNamespace('account-2');
// this will clear current store and reload persisted state from account-2
1.0.1-alpha.4
1 year ago
1.0.1-alpha.3
1 year ago
1.0.1-alpha.2
1 year ago
1.0.1-alpha.1
1 year ago
1.0.1-alpha.0
1 year ago
1.0.0-alpha.0
1 year ago
0.5.0-alpha.0
1 year ago
0.3.0-alpha.0
1 year ago
0.1.0-alpha.0
1 year ago