Search⌘ K
AI Features

Retrieving the Range of Data with a Cursor

Explore how to create and utilize KeyRange objects with IndexedDB to select data ranges. Learn to open cursors on those ranges to iterate and retrieve data from object stores, enhancing data access control in your web apps.

In IndexedDB, a KeyRange object represents a range of keys in an object store. It can retrieve a specific range of records from the object store.

How to create a KeyRange?

There are several ways to create a KeyRange object:

  • Using the only() method

  • Using the bound() method

  • Using the lowerBound() method

  • Using the upperBound() method

Using the only method

This method takes a single key as its argument and creates a KeyRange object that represents a range that only includes that key.

Syntax

let singleKeyRange = IDBKeyRange.only(value);
Syntax of the only method

The value argument is the single key value we want the range to contain. For example, the following code creates a KeyRange object that represents a range that only includes the "A" key:

const keyRange = IDBKeyRange.only("A");
Example of the only method

Using the bound method

...