Class IDBIndex
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
IDBIndex interface of the IndexedDB API provides asynchronous access to an index in a database. An index is a kind of object store for looking up records in another object store, called the referenced object store. You use this interface to retrieve data.
[Value("IDBIndex")]
public class IDBIndex
- Inheritance
-
IDBIndex
- Inherited Members
Remarks
You can retrieve records in an object store through the primary key or by using an index. An index lets you look up records in an object store using properties of the values in the object stores records other than the primary key
The index is a persistent key-value storage where the value part of its records is the key part of a record in the referenced object store. The records in an index are automatically populated whenever records in the referenced object store are inserted, updated, or deleted. Each record in an index can point to only one record in its referenced object store, but several indexes can reference the same object store. When the object store changes, all indexes that refers to the object store are automatically updated.
You can grab a set of keys within a range. To learn more, see 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).
Constructors
IDBIndex()
public IDBIndex()
Properties
KeyPath
The keyPath property of the IDBIndex
interface returns the key path of the current index. If null, this index is not auto-populated.
[Value("keyPath")]
public dynamic KeyPath { get; }
Property Value
- dynamic
Any data type that can be used as a key path.
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).
MultiEntry
The multiEntry read-only property of the
IDBIndex interface returns a boolean value that affects how the index
behaves when the result of evaluating the index's key path yields an array.
[Value("multiEntry")]
public bool MultiEntry { get; }
Property Value
- bool
A boolean value:
Value Effect true There is one record in the index for each item in an array of keys. false There is one record for each key that is an array.
Remarks
This is decided when the index is created, using the
CreateIndex(string, Union106, IDBIndexParameters) method. This method takes an optionaloptions parameter whose multiEntry property is set to true/false.
-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 IDBIndex
interface contains a string which names the index.
[Value("name")]
public string Name { get; set; }
Property Value
- string
A string specifying a name for the index.
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).
ObjectStore
The objectStore property of the IDBIndex
interface returns the object store referenced by the current index.
[Value("objectStore")]
public IDBObjectStore ObjectStore { 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).
Unique
The unique read-only property returns a boolean that
states whether the index allows duplicate keys.
[Value("unique")]
public bool Unique { get; }
Property Value
- bool
A boolean value:
Value Effect trueThe current index does not allow duplicate values for a key. falseThe current index allows duplicate key values.
Remarks
This is decided when the index is created, using the
CreateIndex(string, Union106, IDBIndexParameters) method. This method takes an optional
parameter, unique, which if set to true means that the index
will not be able to accept duplicate entries.
-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
Count(dynamic)
The count() method of the IDBIndex
interface returns an IDBRequest object, and in a separate thread,
returns the number of records within a key range.
[Value("count")]
public IDBRequest Count(dynamic query = null)
Parameters
querydynamic
Returns
- IDBRequest
A 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 key or key range.
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).
Get(dynamic)
The get() method of the IDBIndex
interface returns an IDBRequest object, and, in a separate thread,
finds either the value in the referenced object store that corresponds to the given
key or the first corresponding value, if key is set to an
IDBKeyRange.
[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 found, then a structured clone of it is created and set as theresult of the request object: this returns the record the key is associated
with.
-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 IDBIndex
interface retrieves all objects that are inside the index.
[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
There is a performance cost associated with looking at the value property
of a cursor, because the object is created lazily. To use a feature
like getAll(), the browser has to create all the objects at once. If you
are just interested in looking at each of the keys, for instance, it is more efficient
to use a cursor. If you are trying to get an
array of all the objects in an object store, though, you should
use getAll().
-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 IDBIndex
interface asynchronously retrieves the primary keys of all objects inside the index,
setting them as the result of the request object.
[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
-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 IDBIndex
interface returns an IDBRequest object, and, in a separate thread,
finds either the primary key that corresponds to the given key in this index or the
first corresponding primary key, if key is set to an
IDBKeyRange.
[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 primary key is found, it is set as the result of the request object.
Note that this doesn't return the whole record as Get(dynamic) does.
-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 IDBIndex
interface returns an IDBRequest object, and, in a separate thread,
creates a cursor over the specified key
range.
[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
The method sets the position of the cursor to the appropriate record, based on the
specified direction.
If the key range is not specified or is null, then the range includes all the records.
-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
IDBIndex interface returns an IDBRequest object, and, in
a separate thread, creates a cursor over the specified key range, as arranged by this
index.
[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
The method sets the position of the cursor to the appropriate key, based on the
specified direction.
If the key range is not specified or is null, then the range includes all the keys.
NOTE
Cursors returned by
openKeyCursor()do not
make the referenced value available asIDBIndex.openCursordoes.
This makes obtaining a list of keys much more efficient.
-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).