Class IDBObjectStore
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The IDBObjectStore interface of the IndexedDB API represents an object store in a database. Records within an object store are sorted according to their keys. This sorting enables fast insertion, look-up, and ordered retrieval.
[Value("IDBObjectStore")]
public class IDBObjectStore
- Inheritance
-
IDBObjectStore
- Inherited Members
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Constructors
IDBObjectStore()
public IDBObjectStore()
Properties
AutoIncrement
The autoIncrement read-only property of the
IDBObjectStore interface returns the value of the auto increment flag
for this object store.
[Value("autoIncrement")]
public bool AutoIncrement { get; }
Property Value
- bool
A boolean value:
Value Meaning trueThe object store auto increments. falseThe object store does not auto increment.
Remarks
Note that every object store has its own separate auto increment counter.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
IndexNames
The indexNames read-only property of the
IDBObjectStore interface returns a list of the names of indexes on objects
in this object store.
[Value("indexNames")]
public DOMStringList IndexNames { get; }
Property Value
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
KeyPath
The keyPath read-only property of the
IDBObjectStore interface returns the key path of this object store.
[Value("keyPath")]
public dynamic KeyPath { get; }
Property Value
- dynamic
Any value type.
Remarks
If this property is null, the application must provide a key for each modification
operation.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Name
The name property of the IDBObjectStore
interface indicates the name of this object store.
[Value("name")]
public string Name { get; set; }
Property Value
- string
A string containing the object
store's name.
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Transaction
The transaction read-only property of the
IDBObjectStore interface returns the transaction object to which this
object store belongs.
[Value("transaction")]
public IDBTransaction Transaction { get; }
Property Value
- IDBTransaction
An IDBTransaction object.
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Methods
Add(dynamic, dynamic)
The add() method of the IDBObjectStore interface returns an IDBRequest object, and, in a separate thread, creates a structured clone of the value, and stores the cloned value in the object store. This is for adding new records to an object store.
[Value("add")]
public IDBRequest Add(dynamic value, dynamic key = null)
Parameters
valuedynamickeydynamic
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is the key for the new record.
Remarks
To determine if the add operation has completed successfully, listen for the
transaction's complete event in addition to theIDBObjectStore.add request's success event, because the
transaction may still fail after the success event fires. In other words, the success
event is only triggered when the transaction has been successfully queued.
The add method is an insert only method. If a
record already exists in the object store with the key parameter as its
key, then an error ConstraintError event is fired on the returned request
object. For updating existing records, you should use the
Put(dynamic, dynamic) method instead.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Clear()
The clear() method of the IDBObjectStore
interface creates and immediately returns an IDBRequest object, and
clears this object store in a separate thread. This is for deleting all the current
data out of an object store.
[Value("clear")]
public IDBRequest Clear()
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is
undefined.
Remarks
Clearing an object store consists of removing all records from the object store and
removing all records in indexes that reference the object store. To remove only some of
the records in a store, use Delete(dynamic) passing a key
or IDBKeyRange.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Count(dynamic)
The count() method of the IDBObjectStore
interface returns an IDBRequest object, and, in a separate thread,
returns the total number of records that match the provided key or
IDBKeyRange. If no arguments are provided, it returns the total number
of records in the store.
[Value("count")]
public IDBRequest Count(dynamic query = null)
Parameters
querydynamic
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is the number of records that match the given query.
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
CreateIndex(string, Union106, IDBIndexParameters)
The createIndex() method of the
IDBObjectStore interface creates and returns a new
IDBIndex object in the connected database. It creates a new
field/column defining a new data point for each database record to contain.
[Value("createIndex")]
public IDBIndex CreateIndex(string name, Union106 keyPath, IDBIndexParameters options = null)
Parameters
namestringkeyPathUnion106optionsIDBIndexParameters
Returns
Remarks
Bear in mind that IndexedDB indexes can contain any JavaScript data type;
IndexedDB uses the structured clone algorithm to serialize stored objects, which allows for storage of simple
and complex objects.
Note that this method must be called only from a VersionChange transaction
mode callback.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Delete(dynamic)
The delete() method of the
IDBObjectStore interface returns an IDBRequest object,
and, in a separate thread, deletes the specified record or records.
[Value("delete")]
public IDBRequest Delete(dynamic query)
Parameters
querydynamic
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is
undefined.
Remarks
Either a key or an IDBKeyRange can be passed, allowing one or multiple
records to be deleted from a store. To delete all records in a store, use
Clear().
Bear in mind that if you are using a IDBCursor, you can use
the Delete() method to more efficiently delete the current
record — without having to explicitly look up the record's key.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
DeleteIndex(string)
The deleteIndex() method of the
IDBObjectStore interface destroys the index with the specified name in
the connected database, used during a version upgrade.
[Value("deleteIndex")]
public GlobalObject.Undefined DeleteIndex(string name)
Parameters
namestring
Returns
Remarks
Note that this method must be called only from a VersionChange transaction
mode callback. Note that this method synchronously modifies the
IndexNames property.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Get(dynamic)
The get() method of the IDBObjectStore
interface returns an IDBRequest object, and, in a separate thread,
returns the object selected by the specified key. This is for retrieving
specific records from an object store.
[Value("get")]
public IDBRequest Get(dynamic query)
Parameters
querydynamic
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is the value of the first record matching the given key or key range.
Remarks
If a value is successfully found, then a structured clone of it is created and set as
the result of the
request object.
NOTE
This method produces the same result for: a) a record that doesn't exist in the database and b) a record that has an undefined value.
To tell these situations apart, call theopenCursor()method with the same key. That method provides a cursor if the record exists, and no cursor if it does not.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
GetAll(dynamic, ulong)
The getAll() method of the
IDBObjectStore interface returns an IDBRequest object
containing all objects in the object store matching the specified parameter or all
objects in the store if no parameters are given.
[Value("getAll")]
public IDBRequest GetAll(dynamic query = null, ulong count = 0)
Parameters
querydynamiccountulong
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is an {{jsxref("Array")}} of the values of all records matching the given query, up to the value of
count, ifcountwas supplied.
Remarks
If a value is successfully found, then a structured clone of it is created and set as
the result of the request object.
This method produces the same result for:
To tell these situations apart, you either call
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
GetAllKeys(dynamic, ulong)
The getAllKeys() method of the IDBObjectStore
interface returns an IDBRequest object retrieves record keys for all
objects in the object store matching the specified parameter or all objects in the
store if no parameters are given.
[Value("getAllKeys")]
public IDBRequest GetAllKeys(dynamic query = null, ulong count = 0)
Parameters
querydynamiccountulong
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is an {{jsxref("Array")}} of the keys for all records matching the given query, up to the value of
count, ifcountwas supplied.
Remarks
If a value is successfully found, then a structured clone of it is created and set as
the result of the request object.
This method produces the same result for:
To tell these situations apart, you need to call the
OpenCursor(dynamic, IDBCursorDirection) method with the same key. That
method provides a cursor if the record exists, and no cursor if it does not.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
GetKey(dynamic)
The getKey() method of the
IDBObjectStore interface returns an IDBRequest object,
and, in a separate thread, returns the key selected by the specified query. This is
for retrieving specific records from an object store.
[Value("getKey")]
public IDBRequest GetKey(dynamic query)
Parameters
querydynamic
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is the key for the first record matching the given key or key range.
Remarks
If a key is successfully found, then a structured clone of it is created and set as the
result of the request object.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Index(string)
The index() method of the IDBObjectStore
interface opens a named index in the current object store, after which it can be used
to, for example, return a series of records sorted by that index using a cursor.
[Value("index")]
public IDBIndex Index(string name)
Parameters
namestring
Returns
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
OpenCursor(dynamic, IDBCursorDirection)
The openCursor() method of the
IDBObjectStore interface returns an IDBRequest object,
and, in a separate thread, returns a new IDBCursorWithValue object.
Used for iterating through an object store with a cursor.
[Value("openCursor")]
public IDBRequest OpenCursor(dynamic query = null, IDBCursorDirection direction = IDBCursorDirection.Next)
Parameters
querydynamicdirectionIDBCursorDirection
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is:
Remarks
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
OpenKeyCursor(dynamic, IDBCursorDirection)
The openKeyCursor() method of the
IDBObjectStore interface returns an IDBRequest object
whose result will be set to an IDBCursor that can be used to iterate
through matching results. Used for iterating through the keys of an object store with
a cursor.
[Value("openKeyCursor")]
public IDBRequest OpenKeyCursor(dynamic query = null, IDBCursorDirection direction = IDBCursorDirection.Next)
Parameters
querydynamicdirectionIDBCursorDirection
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is:
Remarks
To determine if the add operation has completed successfully, listen for the
results's success event.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).
Put(dynamic, dynamic)
The put() method of the IDBObjectStore interface updates a given record in a database, or inserts a new record if the given item does not already exist.
[Value("put")]
public IDBRequest Put(dynamic value, dynamic key = null)
Parameters
valuedynamickeydynamic
Returns
- IDBRequest
An IDBRequest object on which subsequent events related to this operation are fired.If the operation is successful, the value of the request's Result property is the key for the new or updated record.
Remarks
It returns an IDBRequest object, and, in a separate thread, creates a structured clone of the value and stores the cloned value in the object store. This is for adding new records, or updating existing records in an object store when the transaction's mode is readwrite. If the record is successfully stored, then a success event is fired on the returned request object with the result set to the key for the stored record, and the transaction set to the transaction in which this object store is opened.
The put method is an update or insert method.
See the Add(dynamic, dynamic) method for an insert only method.
Bear in mind that if you have a IDBCursor to the record you
want to update, updating it with Update(dynamic) is preferable to
using IDBObjectStore.put(). Doing so makes it clear that an existing
record will be updated, instead of a new record being inserted.
-Using IndexedDB
-Starting transactions: IDBDatabase
-Using transactions: IDBTransaction
-Setting a range of keys: IDBKeyRange
-Retrieving and making changes to your data: IDBObjectStore
-Using cursors: IDBCursor
-Reference example: To-do Notifications (View the example live).