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 false.
A key range has an associated upper open flag. Unless otherwise stated it is false.
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 range if both of the following conditions are fulfilled:
The range’s lower bound is null, or it is less than key, or it is both equal to key and the range’s lower open flag is false.
The range’s upper bound is null, or it is greater than key, or it is both equal to key and the range’s upper open flag is false.
If a key range‘s lower open flag is false, the lower bound key of the key range is included in the range itself.
If a key range‘s lower open flag is true, the lower bound key of the key range is excluded from the range itself.
If a key range‘s upper open flag is false, the upper bound key of the key range is included in the range itself.
If a key range‘s upper open flag is true, 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.
To convert a value to a key range with value and optional null disallowed flag, run these steps:
If value is a key range, return value.
If value is undefined or is null, then throw a “
[DataError](https://heycam.github.io/webidl/#dataerror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
if null disallowed flag is true, or return an unbounded key range otherwise.Let key be the result of running convert a value to a key with value. Rethrow any exceptions.
If key is invalid, throw a “
[DataError](https://heycam.github.io/webidl/#dataerror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
.Return a key range containing only key.