4.7. The IDBKeyRange interface
The [IDBKeyRange](#idbkeyrange)
interface represents a key range.
- [
Exposed =(Window ,Worker )]interface {
IDBKeyRange readonly attribute any lower ;readonly attribute any upper ;readonly attribute boolean lowerOpen ;readonly attribute boolean upperOpen ;- // Static construction methods:
- [
NewObject ]static IDBKeyRange only (any );
value - [
NewObject ]static IDBKeyRange lowerBound (any ,
lower optional boolean =
open false );- [
NewObject ]static IDBKeyRange upperBound (any ,
upper optional boolean =
open false );- [
NewObject ]static IDBKeyRange bound (any ,
lower any ,
upper optional boolean =
lowerOpen false ,optional boolean =
upperOpen false );boolean includes (any );
key - };
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:
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)
.Create and return a new key range containing only key.
The lowerBound(lower, open)
method, when invoked, must run these steps:
Let lowerKey be the result of running convert a value to a key with lower. Rethrow any exceptions.
If lowerKey is invalid, throw a “
[DataError](https://heycam.github.io/webidl/#dataerror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
.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:
Let upperKey be the result of running convert a value to a key with upper. Rethrow any exceptions.
If upperKey is invalid, throw a “
[DataError](https://heycam.github.io/webidl/#dataerror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
.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:
Let lowerKey be the result of running convert a value to a key with lower. Rethrow any exceptions.
If lowerKey is invalid, throw a “
[DataError](https://heycam.github.io/webidl/#dataerror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
.Let upperKey be the result of running convert a value to a key with upper. Rethrow any exceptions.
If upperKey is invalid, throw a “
[DataError](https://heycam.github.io/webidl/#dataerror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
.If lowerKey is greater than upperKey, throw a “
[DataError](https://heycam.github.io/webidl/#dataerror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
.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:
Let k be the result of running convert a value to a key with key. Rethrow any exceptions.
If k is invalid, throw a “
[DataError](https://heycam.github.io/webidl/#dataerror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
.Return true if k is in this range, and false otherwise.