local-db-client
v1.1.0
Published
Type safe IndexedDB access.
Downloads
1,043
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: 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();
/** 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();