1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// Copyright 2012 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Wrapper for a IndexedDB key range.
*
*/
goog.provide('goog.db.KeyRange');
/**
* Creates a new IDBKeyRange wrapper object. Should not be created directly,
* instead use one of the static factory methods. For example:
* @see goog.db.KeyRange.bound
* @see goog.db.KeyRange.lowerBound
*
* @param {!IDBKeyRange} range Underlying IDBKeyRange object.
* @constructor
* @final
*/
goog.db.KeyRange = function(range) {
/**
* Underlying IDBKeyRange object.
*
* @type {!IDBKeyRange}
* @private
*/
this.range_ = range;
};
/**
* The IDBKeyRange.
* @type {!Object}
* @private
*/
goog.db.KeyRange.IDB_KEY_RANGE_ =
goog.global.IDBKeyRange || goog.global.webkitIDBKeyRange;
/**
* Creates a new key range for a single value.
*
* @param {IDBKeyType} key The single value in the range.
* @return {!goog.db.KeyRange} The key range.
*/
goog.db.KeyRange.only = function(key) {
return new goog.db.KeyRange(goog.db.KeyRange.IDB_KEY_RANGE_.only(key));
};
/**
* Creates a key range with upper and lower bounds.
*
* @param {IDBKeyType} lower The value of the lower bound.
* @param {IDBKeyType} upper The value of the upper bound.
* @param {boolean=} opt_lowerOpen If true, the range excludes the lower bound
* value.
* @param {boolean=} opt_upperOpen If true, the range excludes the upper bound
* value.
* @return {!goog.db.KeyRange} The key range.
*/
goog.db.KeyRange.bound = function(lower, upper, opt_lowerOpen, opt_upperOpen) {
return new goog.db.KeyRange(
goog.db.KeyRange.IDB_KEY_RANGE_.bound(
lower, upper, opt_lowerOpen, opt_upperOpen));
};
/**
* Creates a key range with a lower bound only, finishes at the last record.
*
* @param {IDBKeyType} lower The value of the lower bound.
* @param {boolean=} opt_lowerOpen If true, the range excludes the lower bound
* value.
* @return {!goog.db.KeyRange} The key range.
*/
goog.db.KeyRange.lowerBound = function(lower, opt_lowerOpen) {
return new goog.db.KeyRange(
goog.db.KeyRange.IDB_KEY_RANGE_.lowerBound(lower, opt_lowerOpen));
};
/**
* Creates a key range with a upper bound only, starts at the first record.
*
* @param {IDBKeyType} upper The value of the upper bound.
* @param {boolean=} opt_upperOpen If true, the range excludes the upper bound
* value.
* @return {!goog.db.KeyRange} The key range.
*/
goog.db.KeyRange.upperBound = function(upper, opt_upperOpen) {
return new goog.db.KeyRange(
goog.db.KeyRange.IDB_KEY_RANGE_.upperBound(upper, opt_upperOpen));
};
/**
* Returns underlying key range object. This is used in ObjectStore's openCursor
* and count methods.
* @return {!IDBKeyRange}
*/
goog.db.KeyRange.prototype.range = function() {
return this.range_;
};
|