Class ydn.db.KeyRange
Platform independent implementation of IDBKeyRange with few helper functions.
A key range is a continuous segment of keys defined by interval by
using lower and upper bound.
To retrieve all keys within a certain interval, you can construct a key range as follow:
Range | Code |
---|---|
All keys ? x | ydn.db.KeyRange.upperBound(x) |
All keys < x | ydn.db.KeyRange.upperBound(x, true)
|
All keys ? y | ydn.db.KeyRange.lowerBound(y) |
All keys > y | ydn.db.KeyRange.lowerBound(y, true) |
All keys ≥ x ≤ y | ydn.db.KeyRange.bound(x, y) |
All keys > x < y | ydn.db.KeyRange.bound(x, y,
true, true) |
All keys > x ≥ y | ydn.db.KeyRange.bound(x, y,
true, false) |
All keys ≤ x < y | ydn.db.KeyRange.bound(x, y,
false, true) |
The key = z | ydn.db.KeyRange.only(z) |
All (string or array) keys start with a | ydn.db.KeyRange.starts(a) |
Constructor
ydn.db.KeyRange(lower, upper,
lowerOpen, upperOpen) version 1
Create a key range object.
Example:
var k1 = new ydn.db.KeyRange(10, 20, false, true);Lower bound and upper bound are either of string, number, Date or simple Array. This union type is annotated as IDbKey thourght out this API documentation. For complete description of valid key value, see IndexedDB key structure.
- Parameters:
- {IDbKey=} lower
- Optional. The value of the lower bound.
- {IDbKey=} upper
- Optional. The value of the upper bound.
- {boolean=} lowerOpen
- Optional. If true, the range excludes the lower bound value.
- {boolean=} upperOpen
- Optional. If true, the range excludes the upper bound value.
Fields
lower
= {IDbKey|undefined}
The value of the lower bound.
upper
= {IDbKey|undefined}
The value of the upper bound.
lowerOpen
= {boolean|undefined}
If true, the range excludes the lower bound
value.
upperOpen
= {boolean|undefined}
If true, the range excludes the upper bound
value.
Methods
bound(lower, upper, lowerOpen,
upperOpen)
Create ydn.db.Key
object using
factory pattern.
ydn.db.Key
object using
factory pattern. - Parameters:
- {IDbKey=} lower
- Optional. The value of the lower bound.
- {IDbKey=} upper
- Optional. The value of the upper bound.
- {boolean=} lowerOpen
- Optional. If true, the range excludes the lower bound value.
- {boolean=} upperOpen
- Optional. If true, the range excludes the upper bound value.
lowerBound(lower, lowerOpen)
Creates a key range with a lower bound only,
finishes at the last record.
- Parameters:
- {IDbKey} lower
- The value of the lower bound.
- {boolean=} lowerOpen
- Optional. If true, the range excludes the lower bound value.
only(value)
Creates a new key range for a single value.
- Parameters:
- {IDbKey} value
- The single value in the range.
upperBound(lower, lowerOpen)
Creates a key range with a upper bound only,
starts at the first record.
- Parameters:
- {IDbKey} upper
- The value of the lower bound.
- {boolean=} upperOpen
- Optional. If true, the range excludes the upper bound value.
starts(value)
Creates a key range having a starting value.
The following key range include all key starting
'abc', such as 'abcd', 'abcz', etc.
var keys_starts_with_abc = ydn.db.Key.starts('abc');The following key range include all key of array value with first element is [5], such as [5, 'a'], [5, 1], etc.
var array_keys_with_element_5 = ydn.db.Key.starts([5]);Similarly,
var array_keys_with_element_abc = ydn.db.Key.starts(['abc']);
- Parameters:
- {string|Array} value
- The starting value.
toJSON()
Get key in JSON format.
- Returns:
- {!Object} object JSON object.