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:
The lower bound is null, or it is less than key, or it is both equal to key and the lower open flag is unset.
The upper bound is null, or it is greater than key, or it is both equal to key and the upper open flag is unset.
If the lower open flag of a key range is unset, the lower bound key of the key range is included in the range itself.
If the lower open flag of a key range is set, the lower bound key of the key range is excluded from the range itself.
If the upper open flag of a key range is unset, the upper bound key of the key range is included in the range itself.
If the upper open flag of a key range is set, the upper bound key of the key range is excluded from the range itself.
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:
If value is a key range, return value.
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.Let key be the result of running the steps to convert a value to a key with value. Rethrow any exceptions.
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)
.Return a key range containing only key.