To search an IndexedDB database by key range or value, we must implement the
IDBKeyrange
object and call on the lowerbound and upperbound methods.
lowerBound()
generates a new key range with only a lower bound. It is closed by default and includes the lower endpoint value. The
upperBound()
function generates a new upper-bound key range, and it is closed by default and includes the upper endpoint value. The following methods include store get,
getAll, getKey, getAllKeys
, or count to perform the actual search. They accept a query argument that can be either an exact key or a key range.
Code Example :
// get one book
books.get('js');
// get books with 'css' <= id <= 'html'
books.getAll(IDBKeyRange.bound('css', 'html'));
// get books with id < 'html'
books.getAll(IDBKeyRange.upperBound('html', true));
// get all books
books.getAll();
// get all keys, where id > 'js'
books.getAllKeys(IDBKeyRange.lowerBound('js', true));?