Debian Codegraph @

closure-library/closure/goog/db/keyrange.js

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