local-db-client
v0.0.2
Published
Type safe IndexedDB access.
Maintainers
Readme
local-db-client
An interface for storing values into IndexedDB with type safety. This uses localforage under-the-hood.
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 = new LocalDbClient({
stringValue: defineShape(''),
numberValue: defineShape(-1),
booleanValue: defineShape(false),
objectValue: 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();
/** Get a stored value. If the stored value is not valid, `undefined` is returned. */
await myClient.get.objectValue();