1.0.1-alpha.4 • Published 3 years 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-keyvalpnpm install @tabular-state/database idb-keyvalyarn add @tabular-state/database idb-keyvalimport { 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-21.0.1-alpha.4
3 years ago
1.0.1-alpha.3
3 years ago
1.0.1-alpha.2
3 years ago
1.0.1-alpha.1
3 years ago
1.0.1-alpha.0
3 years ago
1.0.0-alpha.0
3 years ago
0.5.0-alpha.0
3 years ago
0.3.0-alpha.0
3 years ago
0.1.0-alpha.0
3 years ago