2.9. Key Range

Records can be retrieved from object stores and indexes using either keys or key ranges. A key range is a continuous interval over some data type used for keys.

A key range has an associated lower bound (null or a key).

A key range has an associated upper bound (null or a key).

A key range has an associated lower open flag. Unless otherwise stated it is unset.

A key range has an associated upper open flag. Unless otherwise stated it is unset.

A key range may have a lower bound equal to its upper bound. A key range must not have a lower bound greater than its upper bound.

A key range containing only key has both lower bound and upper bound equal to key.

A key is in a key range if both of the following conditions are fulfilled:

An unbounded key range is a key range that has both lower bound and upper bound equal to null. All keys are in an unbounded key range.

The steps to convert a value to a key range with value and optional null disallowed flag are as follows:

  1. If value is a key range, return value.

  2. If value is undefined or is null, then throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException) if null disallowed flag is set, or return an unbounded key range otherwise.

  3. Let key be the result of running the steps to convert a value to a key with value. Rethrow any exceptions.

  4. If key is invalid, throw a “[DataError](https://www.w3.org/TR/WebIDL-1/#dataerror)[DOMException](https://www.w3.org/TR/WebIDL-1/#idl-DOMException).

  5. Return a key range containing only key.