local-db-client
v2.0.1
Published
Type safe IndexedDB access.
Maintainers
Readme
local-db-client
An interface for storing values into IndexedDB with type safety.
For a synchronous, but more ephemeral, API using LocalStorage, see @electrovir/local-storage-client
Reference docs: https://electrovir.github.io/local-db-client
Instal
npm i local-db-clientUsage
import {defineShape} from 'object-shape-tester';
import {LocalDbClient} from 'local-db-client';
const myClient = await LocalDbClient.createClient({
stringValue: {
shape: defineShape(''),
},
numberValue: {
shape: defineShape(-1),
},
booleanValue: {
shape: defineShape(false),
},
objectValue: {
shape: defineShape({
name: '',
age: 0,
location: '',
}),
},
});
/** Set values with type safety. */
await myClient.set.objectValue({
age: 10,
location: 'Earth',
name: 'Example User',
});
await myClient.set.booleanValue(true);
/** Delete a stored value. */
await myClient.delete.booleanValue();
/** Load a stored value. If the stored value is not valid, `undefined` is returned. */
console.info(myClient.value);
/** Force a value to reload. */
await myClient.load.objectValue();