Path: blob/trunk/third_party/closure/goog/db/keyrange.js
2868 views
// Copyright 2012 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Wrapper for a IndexedDB key range.16*17*/181920goog.provide('goog.db.KeyRange');21222324/**25* Creates a new IDBKeyRange wrapper object. Should not be created directly,26* instead use one of the static factory methods. For example:27* @see goog.db.KeyRange.bound28* @see goog.db.KeyRange.lowerBound29*30* @param {!IDBKeyRange} range Underlying IDBKeyRange object.31* @constructor32* @final33*/34goog.db.KeyRange = function(range) {35/**36* Underlying IDBKeyRange object.37*38* @type {!IDBKeyRange}39* @private40*/41this.range_ = range;42};434445/**46* The IDBKeyRange.47* @type {!Object}48* @private49*/50goog.db.KeyRange.IDB_KEY_RANGE_ =51goog.global.IDBKeyRange || goog.global.webkitIDBKeyRange;525354/**55* Creates a new key range for a single value.56*57* @param {IDBKeyType} key The single value in the range.58* @return {!goog.db.KeyRange} The key range.59*/60goog.db.KeyRange.only = function(key) {61return new goog.db.KeyRange(goog.db.KeyRange.IDB_KEY_RANGE_.only(key));62};636465/**66* Creates a key range with upper and lower bounds.67*68* @param {IDBKeyType} lower The value of the lower bound.69* @param {IDBKeyType} upper The value of the upper bound.70* @param {boolean=} opt_lowerOpen If true, the range excludes the lower bound71* value.72* @param {boolean=} opt_upperOpen If true, the range excludes the upper bound73* value.74* @return {!goog.db.KeyRange} The key range.75*/76goog.db.KeyRange.bound = function(lower, upper, opt_lowerOpen, opt_upperOpen) {77return new goog.db.KeyRange(78goog.db.KeyRange.IDB_KEY_RANGE_.bound(79lower, upper, opt_lowerOpen, opt_upperOpen));80};818283/**84* Creates a key range with a lower bound only, finishes at the last record.85*86* @param {IDBKeyType} lower The value of the lower bound.87* @param {boolean=} opt_lowerOpen If true, the range excludes the lower bound88* value.89* @return {!goog.db.KeyRange} The key range.90*/91goog.db.KeyRange.lowerBound = function(lower, opt_lowerOpen) {92return new goog.db.KeyRange(93goog.db.KeyRange.IDB_KEY_RANGE_.lowerBound(lower, opt_lowerOpen));94};959697/**98* Creates a key range with a upper bound only, starts at the first record.99*100* @param {IDBKeyType} upper The value of the upper bound.101* @param {boolean=} opt_upperOpen If true, the range excludes the upper bound102* value.103* @return {!goog.db.KeyRange} The key range.104*/105goog.db.KeyRange.upperBound = function(upper, opt_upperOpen) {106return new goog.db.KeyRange(107goog.db.KeyRange.IDB_KEY_RANGE_.upperBound(upper, opt_upperOpen));108};109110111/**112* Returns underlying key range object. This is used in ObjectStore's openCursor113* and count methods.114* @return {!IDBKeyRange}115*/116goog.db.KeyRange.prototype.range = function() {117return this.range_;118};119120121