4.7. The IDBKeyRange interface

The [IDBKeyRange](#idbkeyrange) interface represents a key range.

  1. [Exposed=(Window,Worker)]
  2. interface IDBKeyRange {
  3. readonly attribute any lower;
  4. readonly attribute any upper;
  5. readonly attribute boolean lowerOpen;
  6. readonly attribute boolean upperOpen;
  7.  
  8. // Static construction methods:
  9. [NewObject] static IDBKeyRange only(any value);
  10. [NewObject] static IDBKeyRange lowerBound(any lower, optional boolean open = false);
  11. [NewObject] static IDBKeyRange upperBound(any upper, optional boolean open = false);
  12. [NewObject] static IDBKeyRange bound(any lower,
  13. any upper,
  14. optional boolean lowerOpen = false,
  15. optional boolean upperOpen = false);
  16.  
  17. boolean includes(any key);
  18. };

range . [lower](#dom-idbkeyrange-lower)

Returns the range’s lower bound, or undefined if none.

range . [upper](#dom-idbkeyrange-upper)

Returns the range’s upper bound, or undefined if none.

range . [lowerOpen](#dom-idbkeyrange-loweropen)

Returns the range’s lower open flag.

range . [upperOpen](#dom-idbkeyrange-upperopen)

Returns the range’s upper open flag.

The lower attribute’s getter must return result of running convert a key to a value with this‘s lower bound if it is not null, or undefined otherwise.

The upper attribute’s getter must return the result of running convert a key to a value with this‘s upper bound if it is not null, or undefined otherwise.

The lowerOpen attribute’s getter must return this‘s lower open flag.

The upperOpen attribute’s getter must return this‘s upper open flag.

range = [IDBKeyRange](#idbkeyrange) . [only](#dom-idbkeyrange-only)(key)

Returns a new [IDBKeyRange](#idbkeyrange) spanning only key.

range = [IDBKeyRange](#idbkeyrange) . [lowerBound](#dom-idbkeyrange-lowerbound)(key [, open = false])

Returns a new [IDBKeyRange](#idbkeyrange) starting at key with no upper bound. If open is true, key is not included in the range.

range = [IDBKeyRange](#idbkeyrange) . [upperBound](#dom-idbkeyrange-upperbound)(key [, open = false])

Returns a new [IDBKeyRange](#idbkeyrange) with no lower bound and ending at key. If open is true, key is not included in the range.

range = [IDBKeyRange](#idbkeyrange) . [bound](#dom-idbkeyrange-bound)(lower, upper [, lowerOpen = false [, upperOpen = false]])

Returns a new [IDBKeyRange](#idbkeyrange) spanning from lower to upper. If lowerOpen is true, lower is not included in the range. If upperOpen is true, upper is not included in the range.

The only(value) method, when invoked, must run these steps:

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

  2. If key is invalid, throw a “[DataError](https://heycam.github.io/webidl/#dataerror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

  3. Create and return a new key range containing only key.

The lowerBound(lower, open) method, when invoked, must run these steps:

  1. Let lowerKey be the result of running convert a value to a key with lower. Rethrow any exceptions.

  2. If lowerKey is invalid, throw a “[DataError](https://heycam.github.io/webidl/#dataerror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

  3. Create and return a new key range with lower bound set to lowerKey, lower open flag set to open, upper bound set to null, and upper open flag set to true.

The upperBound(upper, open) method, when invoked, must run these steps:

  1. Let upperKey be the result of running convert a value to a key with upper. Rethrow any exceptions.

  2. If upperKey is invalid, throw a “[DataError](https://heycam.github.io/webidl/#dataerror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

  3. Create and return a new key range with lower bound set to null, lower open flag set to true, upper bound set to upperKey, and upper open flag set to open.

The bound(lower, upper, lowerOpen, upperOpen) method, when invoked, must run these steps:

  1. Let lowerKey be the result of running convert a value to a key with lower. Rethrow any exceptions.

  2. If lowerKey is invalid, throw a “[DataError](https://heycam.github.io/webidl/#dataerror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

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

  4. If upperKey is invalid, throw a “[DataError](https://heycam.github.io/webidl/#dataerror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

  5. If lowerKey is greater than upperKey, throw a “[DataError](https://heycam.github.io/webidl/#dataerror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

  6. Create and return a new key range with lower bound set to lowerKey, lower open flag set to lowerOpen, upper bound set to upperKey and upper open flag set to upperOpen.

range . [includes](#dom-idbkeyrange-includes)(key)

Returns true if key is included in the range, and false otherwise.

The includes(key) method, when invoked, must run these steps:

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

  2. If k is invalid, throw a “[DataError](https://heycam.github.io/webidl/#dataerror)[DOMException](https://heycam.github.io/webidl/#idl-DOMException).

  3. Return true if k is in this range, and false otherwise.