keyrange.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. * @fileoverview Wrapper for a IndexedDB key range.
  16. *
  17. */
  18. goog.provide('goog.db.KeyRange');
  19. /**
  20. * Creates a new IDBKeyRange wrapper object. Should not be created directly,
  21. * instead use one of the static factory methods. For example:
  22. * @see goog.db.KeyRange.bound
  23. * @see goog.db.KeyRange.lowerBound
  24. *
  25. * @param {!IDBKeyRange} range Underlying IDBKeyRange object.
  26. * @constructor
  27. * @final
  28. */
  29. goog.db.KeyRange = function(range) {
  30. /**
  31. * Underlying IDBKeyRange object.
  32. *
  33. * @type {!IDBKeyRange}
  34. * @private
  35. */
  36. this.range_ = range;
  37. };
  38. /**
  39. * The IDBKeyRange.
  40. * @type {!Object}
  41. * @private
  42. */
  43. goog.db.KeyRange.IDB_KEY_RANGE_ =
  44. goog.global.IDBKeyRange || goog.global.webkitIDBKeyRange;
  45. /**
  46. * Creates a new key range for a single value.
  47. *
  48. * @param {IDBKeyType} key The single value in the range.
  49. * @return {!goog.db.KeyRange} The key range.
  50. */
  51. goog.db.KeyRange.only = function(key) {
  52. return new goog.db.KeyRange(goog.db.KeyRange.IDB_KEY_RANGE_.only(key));
  53. };
  54. /**
  55. * Creates a key range with upper and lower bounds.
  56. *
  57. * @param {IDBKeyType} lower The value of the lower bound.
  58. * @param {IDBKeyType} upper The value of the upper bound.
  59. * @param {boolean=} opt_lowerOpen If true, the range excludes the lower bound
  60. * value.
  61. * @param {boolean=} opt_upperOpen If true, the range excludes the upper bound
  62. * value.
  63. * @return {!goog.db.KeyRange} The key range.
  64. */
  65. goog.db.KeyRange.bound = function(lower, upper, opt_lowerOpen, opt_upperOpen) {
  66. return new goog.db.KeyRange(
  67. goog.db.KeyRange.IDB_KEY_RANGE_.bound(
  68. lower, upper, opt_lowerOpen, opt_upperOpen));
  69. };
  70. /**
  71. * Creates a key range with a lower bound only, finishes at the last record.
  72. *
  73. * @param {IDBKeyType} lower The value of the lower bound.
  74. * @param {boolean=} opt_lowerOpen If true, the range excludes the lower bound
  75. * value.
  76. * @return {!goog.db.KeyRange} The key range.
  77. */
  78. goog.db.KeyRange.lowerBound = function(lower, opt_lowerOpen) {
  79. return new goog.db.KeyRange(
  80. goog.db.KeyRange.IDB_KEY_RANGE_.lowerBound(lower, opt_lowerOpen));
  81. };
  82. /**
  83. * Creates a key range with a upper bound only, starts at the first record.
  84. *
  85. * @param {IDBKeyType} upper The value of the upper bound.
  86. * @param {boolean=} opt_upperOpen If true, the range excludes the upper bound
  87. * value.
  88. * @return {!goog.db.KeyRange} The key range.
  89. */
  90. goog.db.KeyRange.upperBound = function(upper, opt_upperOpen) {
  91. return new goog.db.KeyRange(
  92. goog.db.KeyRange.IDB_KEY_RANGE_.upperBound(upper, opt_upperOpen));
  93. };
  94. /**
  95. * Returns underlying key range object. This is used in ObjectStore's openCursor
  96. * and count methods.
  97. * @return {!IDBKeyRange}
  98. */
  99. goog.db.KeyRange.prototype.range = function() {
  100. return this.range_;
  101. };