Base functionality used throughout XY Labs TypeScript/JavaScript libraries
npm install @xylabs/indexed-db[![logo][]](https://xylabs.com)
[![main-build][]][main-build-link]
[![npm-badge][]][npm-link]
[![npm-downloads-badge][]][npm-link]
[![jsdelivr-badge][]][jsdelivr-link]
[![npm-license-badge][]](LICENSE)
[![codacy-badge][]][codacy-link]
[![codeclimate-badge][]][codeclimate-link]
[![snyk-badge][]][snyk-link]
[![socket-badge][]][socket-link]
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
@xylabs/indexed-db
*
- IndexDirection
- IndexDescription
- buildStandardIndexName
- checkDbNeedsUpgrade
- createStoreDuringUpgrade
- getExistingIndexes
- withDb
- withDbByVersion
- withReadOnlyStore
- withReadWriteStore
- withStore
*
An IndexedDB key/value store.
T extends DBSchema
S extends StoreNames\<T\>
- KeyValueStore\<StoreValue\<T, S\>, StoreKey\<T, S\>\>
``ts`
new IndexedDbKeyValueStore
#### dbName
string
#### storeName
S
IndexedDbKeyValueStore\<T, S\>
`ts`
readonly dbName: string;
*
`ts`
readonly storeName: S;
`ts`
optional clear(): Promise
Promise\<void\>
`ts`
KeyValueStore.clear
*
`ts`
delete(key): Promise
#### key
StoreKey\<T, S\>
Promise\<void\>
`ts`
KeyValueStore.delete
*
`ts`
get(key): Promise
Returns a promise that resolves to the value for the given key.
#### key
StoreKey\<T, S\>
The key to get the value for.
Promise\<undefined \| StoreValue\<T, S\>\>
`ts`
KeyValueStore.get
*
`ts`
optional keys(): Promise
The keys an array of keys.
Promise\<StoreKey\<T, S\>[]\>
`ts`
KeyValueStore.keys
*
`ts`
set(key, value): Promise
#### key
StoreKey\<T, S\>
#### value
StoreValue\<T, S\>
Promise\<void\>
`ts`
KeyValueStore.set
*
`ts`
withDb
#### R
R = StoreValue\<T, S\>
#### callback
(db) => R \| Promise\<R\>
Promise\<R\>
*
`ts`
function buildStandardIndexName(index): string;
Given an index description, this will build the index
name in standard form
The index description
string
The index name in standard form
*
`ts`
function checkDbNeedsUpgrade(
dbName,
stores,
logger?): Promise
string
Record\<string, IndexDescription[]\>
Logger
Promise\<number\>
*
`ts`
function createStoreDuringUpgrade
db,
storeName,
indexes,
logger?): void;
DBTypes extends unknown = unknown
IDBPDatabase\<DBTypes\>
StoreNames\<DBTypes\>
Logger
void
*
`ts`
function getExistingIndexes
db,
storeName,
logger?): Promise
T extends object = object
string | IDBPDatabase\<ObjectStore\<T\>\>
StoreNames\<ObjectStore\<T\>\>
Logger
Promise\<null \| IndexDescription[]\>
*
`ts`
function withDb
dbName,
callback,
expectedIndexes?,
logger?,
lock?): Promise
DBTypes extends unknown = unknown
R = object
string
(db) => R \| Promise\<R\>
Record\<string, IndexDescription[]\>
Logger
boolean = true
Promise\<R\>
*
`ts`
function withDbByVersion
dbName,
callback,
version?,
expectedIndexes?,
logger?,
lock?): Promise
DBTypes extends unknown = unknown
R = object
string
(db) => R \| Promise\<R\>
number
Record\<string, IndexDescription[]\>
Logger
boolean = true
Promise\<R\>
*
`ts`
function withReadOnlyStore
db,
storeName,
callback,
logger?): Promise
T extends object = object
R = T
IDBPDatabase\<ObjectStore\<T\>\>
StoreNames\<ObjectStore\<T\>\>
(store) => R \| Promise\<R\>
Logger
Promise\<R\>
*
`ts`
function withReadWriteStore
db,
storeName,
callback,
logger?): Promise
T extends object = object
R = T
IDBPDatabase\<ObjectStore\<T\>\>
StoreNames\<ObjectStore\<T\>\>
(store) => R \| Promise\<R\>
Logger
Promise\<R\>
*
`ts`
function withStore
db,
storeName,
callback,
mode,
logger?): Promise
T extends object = object
R = T
M extends "readonly" \| "readwrite" = "readonly"
IDBPDatabase\<ObjectStore\<T\>\>
StoreNames\<ObjectStore\<T\>\>
(store) => R \| Promise\<R\>
M
Logger
Promise\<R\>
*
T extends EmptyObject = EmptyObject
`ts`
[s: string]: T
*
`ts`
type IndexDescription = object;
Description of index(es) to be created on a store
`ts`
key: Record
The key(s) to index
*
`ts`
optional multiEntry: boolean;
Is the indexed value an array
*
`ts`
optional unique: boolean;
If true, the index must enforce uniqueness on the key
*
`ts`
type IndexDirection = -1 | 1;
The index direction (1 for ascending, -1 for descending)
*
`ts``
const IndexSeparator: "-" = '-';
Part of sdk-js
- Arie Trouw (arietrouw.com)
- Matt Jones
- Joel Carter
- Jordan Trouw
> See the LICENSE file for license details
[logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
[main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg
[main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml
[npm-badge]: https://img.shields.io/npm/v/@xylabs/indexed-db.svg
[npm-link]: https://www.npmjs.com/package/@xylabs/indexed-db
[codacy-badge]: https://app.codacy.com/project/badge/Grade/c8e15e14f37741c18cfb47ac7245c698
[codacy-link]: https://www.codacy.com/gh/xylabs/sdk-js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=xylabs/sdk-js&utm_campaign=Badge_Grade
[codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability
[codeclimate-link]: https://codeclimate.com/github/xylabs/sdk-js/maintainability
[snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json
[snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json
[npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/indexed-db
[npm-license-badge]: https://img.shields.io/npm/l/@xylabs/indexed-db
[jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/indexed-db/badge
[jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/indexed-db
[socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/indexed-db
[socket-link]: https://socket.dev/npm/package/@xylabs/indexed-db