The goog.db.ObjectStore Class

goog.db.ObjectStore(store)

Creates an IDBObjectStore wrapper object. Object stores have methods for storing and retrieving records, and are accessed through a transaction object. They also have methods for creating indexes associated with the object store. They can only be created when setting the version of the database. Should not be created directly, access object stores through transactions.

store {!IDBObjectStore}
The backing IndexedDb object.
@see
goog.db.IndexedDb#setVersion
@see
goog.db.Transaction#objectStore

.add(value, opt_key)

Adds an object to the object store. Requires that there is no object with the same key already present.

value {!Object}
The value to add.
opt_key {!Object=}
The key to use. Cannot be used if the keyPath was specified for the object store. If the keyPath was not specified but autoIncrement was not enabled, it must be used.
returns {!goog.async.Deferred}
The deferred add request.

.clear()

Deletes all objects from the store.

returns {!goog.async.Deferred}
The deferred clear request.

.createIndex(name, keyPath, opt_parameters)

Creates an index in this object store. Can only be called inside the callback for the Deferred returned from goog.db.IndexedDb#setVersion.

name {string}
Name of the index to create.
keyPath {string}
Attribute to index on.
opt_parameters {!Object=}
Optional parameters object. The only available option is unique, which defaults to false. If unique is true, the index will enforce that there is only ever one object in the object store for each unique value it indexes on.
returns {goog.db.Index}
The newly created, wrapped index.
@throws
{goog.db.Error} In case of an error creating the index.

.deleteIndex(name)

Deletes an index from the object store. Can only be called inside the callback for the Deferred returned from goog.db.IndexedDb#setVersion.

name {string}
Name of the index to delete.
@throws
{goog.db.Error} In case of an error deleting the index.

.get(key)

Gets an object from the store. If no object is present with that key the result is {@code undefined}.

key {!Object}
The key to look up.
returns {!goog.async.Deferred}
The deferred get request.

.getAll(opt_range, opt_direction)

Gets all objects from the store and returns them as an array.

opt_range {!goog.db.KeyRange=}
The key range. If undefined iterates over the whole object store.
opt_direction {!goog.db.Cursor.Direction=}
The direction. If undefined moves in a forward direction with duplicates.
returns {!goog.async.Deferred}
The deferred getAll request.

.getIndex(name)

Gets an index.

name {string}
Name of the index to fetch.
returns {goog.db.Index}
The requested wrapped index.
@throws
{goog.db.Error} In case of an error getting the index.

.getName()

returns {string}
The name of the object store.

.openCursor(opt_range, opt_direction)

Opens a cursor over the specified key range. Returns a cursor object which is able to iterate over the given range. Example usage: var cursor = objectStore.openCursor(goog.db.Range.bound('a', 'c')); var key = goog.events.listen( cursor, goog.db.Cursor.EventType.NEW_DATA, function() { // Do something with data. cursor.next(); }); goog.events.listenOnce( cursor, goog.db.Cursor.EventType.COMPLETE, function() { // Clean up listener, and perform a finishing operation on the data. goog.events.unlistenByKey(key); });

opt_range {!goog.db.KeyRange=}
The key range. If undefined iterates over the whole object store.
opt_direction {!goog.db.Cursor.Direction=}
The direction. If undefined moves in a forward direction with duplicates.
returns {!goog.db.Cursor}
The cursor.
@throws
{goog.db.Error} If there was a problem opening the cursor.
@suppress
{accessControls}

.put(value, opt_key)

Adds an object to the object store. Replaces existing objects with the same key.

value {!Object}
The value to put.
opt_key {!Object=}
The key to use. Cannot be used if the keyPath was specified for the object store. If the keyPath was not specified but autoIncrement was not enabled, it must be used.
returns {!goog.async.Deferred}
The deferred put request.

.remove(key)

Removes an object from the store. No-op if there is no object present with the given key.

key {!Object}
The key to remove objects under.
returns {!goog.async.Deferred}
The deferred remove request.