IDBObjectStore

external class IDBObjectStore(source)

This example shows a variety of different uses of object stores, from updating the data structure with IDBObjectStore.createIndex inside an onupgradeneeded function, to adding a new item to our object store with IDBObjectStore.add. For a full working example, see our To-do Notifications app (view example live.)

MDN Reference

Properties

Link copied to clipboard

Returns true if the store has a key generator, and false otherwise.

Link copied to clipboard

Returns a list of the names of indexes in the store.

Link copied to clipboard

Returns the key path of the store, or null if none.

Link copied to clipboard

Returns the name of the store.

Link copied to clipboard

Returns the associated transaction.

Functions

Link copied to clipboard
fun add(value: Any?, key: IDBValidKey = definedExternally): IDBRequest<IDBValidKey>

Adds or updates a record in store with the given value and key.

Link copied to clipboard

Deletes all records in store.

Link copied to clipboard

fun count(query: IDBValidKey = definedExternally): IDBRequest<Int>

Retrieves the number of records matching the given key or key range in query.

Link copied to clipboard
fun createIndex(name: String, keyPath: ReadonlyArray<String>, options: IDBIndexParameters = definedExternally): IDBIndex

fun createIndex(name: String, keyPath: String, options: IDBIndexParameters = definedExternally): IDBIndex

Creates a new index in store with the given name, keyPath and options and returns a new IDBIndex. If the keyPath and options define constraints that cannot be satisfied with the data already in store the upgrade transaction will abort with a "ConstraintError" DOMException.

Link copied to clipboard

Deletes records in store with the given key or in the given key range in query.

Link copied to clipboard
fun deleteIndex(name: String)

Deletes the index in store with the given name.

Link copied to clipboard
operator fun get(query: IDBKeyRange): IDBRequest<*>

operator fun get(query: IDBValidKey): IDBRequest<*>

Retrieves the value of the first record matching the given key or key range in query.

Link copied to clipboard
fun getAll(query: IDBKeyRange?, count: Int = definedExternally): IDBRequest<ReadonlyArray<*>>

fun getAll(query: IDBValidKey? = definedExternally, count: Int = definedExternally): IDBRequest<ReadonlyArray<*>>

Retrieves the values of the records matching the given key or key range in query (up to count if given).

Link copied to clipboard
fun getAllKeys(query: IDBKeyRange?, count: Int = definedExternally): IDBRequest<ReadonlyArray<IDBValidKey>>

fun getAllKeys(query: IDBValidKey? = definedExternally, count: Int = definedExternally): IDBRequest<ReadonlyArray<IDBValidKey>>

Retrieves the keys of records matching the given key or key range in query (up to count if given).

Link copied to clipboard

Retrieves the key of the first record matching the given key or key range in query.

Link copied to clipboard
Link copied to clipboard
fun openCursor(query: IDBKeyRange?, direction: IDBCursorDirection = definedExternally): IDBRequest<IDBCursorWithValue?>

fun openCursor(query: IDBValidKey? = definedExternally, direction: IDBCursorDirection = definedExternally): IDBRequest<IDBCursorWithValue?>

Opens a cursor over the records matching query, ordered by direction. If query is null, all records in store are matched.

Link copied to clipboard
fun openKeyCursor(query: IDBKeyRange?, direction: IDBCursorDirection = definedExternally): IDBRequest<IDBCursor?>

fun openKeyCursor(query: IDBValidKey? = definedExternally, direction: IDBCursorDirection = definedExternally): IDBRequest<IDBCursor?>

Opens a cursor with key only flag set over the records matching query, ordered by direction. If query is null, all records in store are matched.

Link copied to clipboard
fun put(value: Any?, key: IDBValidKey = definedExternally): IDBRequest<IDBValidKey>

Adds or updates a record in store with the given value and key.