Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

IDBObjectStore

import { IDBObjectStore } from "https://raw.githubusercontent.com/aaronhuggins/indexeddb/main/ponyfill.ts";

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.)

interface IDBObjectStore {
readonly autoIncrement: boolean;
readonly indexNames: DOMStringList;
readonly keyPath: string | string[];
name: string;
prototype: IDBObjectStore;
readonly transaction: IDBTransaction;
add(value: any, key?: IDBValidKey): IDBRequest<IDBValidKey>;
clear(): IDBRequest<undefined>;
count(query?: IDBValidKey | IDBKeyRange): IDBRequest<number>;
createIndex(
name: string,
keyPath: string | string[],
options?: IDBIndexParameters,
): IDBIndex;
delete(query: IDBValidKey | IDBKeyRange): IDBRequest<undefined>;
deleteIndex(name: string): void;
get(query: IDBValidKey | IDBKeyRange): IDBRequest<any>;
getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number): IDBRequest<any[]>;
getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number): IDBRequest<IDBValidKey[]>;
getKey(query: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined>;
index(name: string): IDBIndex;
openCursor(query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null>;
openKeyCursor(query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): IDBRequest<IDBCursor | null>;
put(value: any, key?: IDBValidKey): IDBRequest<IDBValidKey>;
}
const IDBObjectStore;

§Properties

§
readonly autoIncrement: boolean
[src]

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

§
readonly indexNames: DOMStringList
[src]

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

§
readonly keyPath: string | string[]
[src]

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

§
name: string
[src]

Returns the name of the store.

§
readonly transaction: IDBTransaction
[src]

Returns the associated transaction.

§Methods

§
add(value: any, key?: IDBValidKey): IDBRequest<IDBValidKey>
[src]

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

If the store uses in-line keys and key is specified a "DataError" DOMException will be thrown.

If put() is used, any existing record with the key will be replaced. If add() is used, and if a record with the key already exists the request will fail, with request's error set to a "ConstraintError" DOMException.

If successful, request's result will be the record's key.

§
clear(): IDBRequest<undefined>
[src]

Deletes all records in store.

If successful, request's result will be undefined.

§
count(query?: IDBValidKey | IDBKeyRange): IDBRequest<number>
[src]

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

If successful, request's result will be the count.

§
createIndex(
name: string,
keyPath: string | string[],
options?: IDBIndexParameters,
): IDBIndex
[src]

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.

Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.

§
delete(query: IDBValidKey | IDBKeyRange): IDBRequest<undefined>
[src]

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

If successful, request's result will be undefined.

§
deleteIndex(name: string): void
[src]

Deletes the index in store with the given name.

Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.

§
get(query: IDBValidKey | IDBKeyRange): IDBRequest<any>
[src]

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

If successful, request's result will be the value, or undefined if there was no matching record.

§
getAll(query?: IDBValidKey | IDBKeyRange | null, count?: number): IDBRequest<any[]>
[src]

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

If successful, request's result will be an Array of the values.

§
getAllKeys(query?: IDBValidKey | IDBKeyRange | null, count?: number): IDBRequest<IDBValidKey[]>
[src]

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

If successful, request's result will be an Array of the keys.

§
getKey(query: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined>
[src]

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

If successful, request's result will be the key, or undefined if there was no matching record.

§
index(name: string): IDBIndex
[src]
§
openCursor(query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null>
[src]

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

If successful, request's result will be an IDBCursorWithValue pointing at the first matching record, or null if there were no matching records.

§
openKeyCursor(query?: IDBValidKey | IDBKeyRange | null, direction?: IDBCursorDirection): IDBRequest<IDBCursor | null>
[src]

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.

If successful, request's result will be an IDBCursor pointing at the first matching record, or null if there were no matching records.

§
put(value: any, key?: IDBValidKey): IDBRequest<IDBValidKey>
[src]

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

If the store uses in-line keys and key is specified a "DataError" DOMException will be thrown.

If put() is used, any existing record with the key will be replaced. If add() is used, and if a record with the key already exists the request will fail, with request's error set to a "ConstraintError" DOMException.

If successful, request's result will be the record's key.