idb-take
Take values from IDBStore or IDBIndex
idb-take
is a set of functions on top of .openCursor()
functionality.
Think about it as improved IndexedDB 2.0's getAll(range, limit) method, which in addition to limit
argument accepts unique
, offset
and reverse
.
Installation
npm install --save idb-take
Example
// let's assume you have IndexedDB database with 'books' store and `byFrequency` indexconst db = await // query storeconst store = dbawait // find all keys matching `a` patternawait // page=3await // get first value // query indexconst index = dbindex'byFrequency'await await // in reverse orderawait // get last value
API
Each function accepts 3 arguments:
store
- an instance ofIDBStore
orIDBIndex
. It also integrates with high level libraries which support.openCursor()
method (for example: treo).range
(optional) -IDBKeyRange
instance or any idb-range argumentopts
(optional) - filter options:limit
- limit amount or returned valuesoffset
- skip valuesreverse
- get values in reverse order usingprev
orprevunique
when open cursor.unique
- get only unique values usingprevunique
ornextunique
(applicable only forIDBIndex
).
take(store, [range], [opts])
Take values from store
, which satisfy range
criteria.
await await
takeOne(store, [range], [opts])
Take first value.
takeRight(store, [range], [opts])
Take values in reverse order.
takeRightOne(store, [range], [opts])
Take last value.