Skip to content

IDBObjectStore

Types

t

type t = WebAPI.IndexedDbTypes.idbObjectStore = {
mutable name: string,
keyPath: Null.t<unknown>,
indexNames: WebAPI.DOM.domStringList,
transaction: WebAPI.IndexedDbTypes.idbTransaction,
autoIncrement: bool,
}

Record fields

name
string

Returns the name of the store. Read more on MDN

keyPath
Null.t<unknown>

Returns the key path of the store, or null if none. Read more on MDN

indexNames

Returns a list of the names of indexes in the store. Read more on MDN

transaction
WebAPI.IndexedDbTypes.idbTransaction

Returns the associated transaction. Read more on MDN

autoIncrement
bool

Returns true if the store has a key generator, and false otherwise. Read more on MDN

Values

add

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. Read more on MDN

let add: (
WebAPI.IndexedDbTypes.idbObjectStore,
~value: JSON.t,
~key: WebAPI.IndexedDbTypes.idbValidKey=?,
) => WebAPI.IndexedDbTypes.idbRequest<
WebAPI.IndexedDbTypes.idbValidKey,
>

Parameters

~value: JSON.t
~key: WebAPI.IndexedDbTypes.idbValidKey=?

Return type

WebAPI.IndexedDbTypes.idbRequest<WebAPI.IndexedDbTypes.idbValidKey>

clear

Deletes all records in store.

If successful, request's result will be undefined. Read more on MDN

let clear: WebAPI.IndexedDbTypes.idbObjectStore => WebAPI.IndexedDbTypes.idbRequest<
unit,
>

Parameters

Return type

WebAPI.IndexedDbTypes.idbRequest<unit>

count

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

If successful, request's result will be the count. Read more on MDN

let count: (
WebAPI.IndexedDbTypes.idbObjectStore,
~query: unknown=?,
) => WebAPI.IndexedDbTypes.idbRequest<int>

Parameters

~query: unknown=?

Return type

WebAPI.IndexedDbTypes.idbRequest<int>

createIndex

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. Read more on MDN

let createIndex: (
WebAPI.IndexedDbTypes.idbObjectStore,
~name: string,
~keyPath: string,
~options: WebAPI.IndexedDbTypes.idbIndexParameters=?,
) => WebAPI.IndexedDbTypes.idbIndex

Parameters

~name: string
~keyPath: string
~options: WebAPI.IndexedDbTypes.idbIndexParameters=?

Return type

WebAPI.IndexedDbTypes.idbIndex

createIndex2

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. Read more on MDN

let createIndex2: (
WebAPI.IndexedDbTypes.idbObjectStore,
~name: string,
~keyPath: array<string>,
~options: WebAPI.IndexedDbTypes.idbIndexParameters=?,
) => WebAPI.IndexedDbTypes.idbIndex

Parameters

~name: string
~keyPath: array<string>
~options: WebAPI.IndexedDbTypes.idbIndexParameters=?

Return type

WebAPI.IndexedDbTypes.idbIndex

delete

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

If successful, request's result will be undefined. Read more on MDN

let delete: (
WebAPI.IndexedDbTypes.idbObjectStore,
unknown,
) => WebAPI.IndexedDbTypes.idbRequest<unit>

Parameters

unknown

Return type

WebAPI.IndexedDbTypes.idbRequest<unit>

deleteIndex

Deletes the index in store with the given name.

Throws an "InvalidStateError" DOMException if not called within an upgrade transaction. Read more on MDN

let deleteIndex: (WebAPI.IndexedDbTypes.idbObjectStore, string) => unit

Parameters

string

Return type

unit

get

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. Read more on MDN

let get: (
WebAPI.IndexedDbTypes.idbObjectStore,
unknown,
) => WebAPI.IndexedDbTypes.idbRequest<option<JSON.t>>

Parameters

unknown

Return type

WebAPI.IndexedDbTypes.idbRequest<option<JSON.t>>

getAll

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. Read more on MDN

let getAll: (
WebAPI.IndexedDbTypes.idbObjectStore,
~query: unknown=?,
~count: int=?,
) => WebAPI.IndexedDbTypes.idbRequest<array<JSON.t>>

Parameters

~query: unknown=?
~count: int=?

Return type

WebAPI.IndexedDbTypes.idbRequest<array<JSON.t>>

getAllKeys

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. Read more on MDN

let getAllKeys: (
WebAPI.IndexedDbTypes.idbObjectStore,
~query: unknown=?,
~count: int=?,
) => WebAPI.IndexedDbTypes.idbRequest<
array<WebAPI.IndexedDbTypes.idbValidKey>,
>

Parameters

~query: unknown=?
~count: int=?

Return type

WebAPI.IndexedDbTypes.idbRequest<array<WebAPI.IndexedDbTypes.idbValidKey>>

getKey

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. Read more on MDN

let getKey: (
WebAPI.IndexedDbTypes.idbObjectStore,
unknown,
) => WebAPI.IndexedDbTypes.idbRequest<
option<WebAPI.IndexedDbTypes.idbValidKey>,
>

Parameters

unknown

Return type

WebAPI.IndexedDbTypes.idbRequest<option<WebAPI.IndexedDbTypes.idbValidKey>>

index

let index: (
WebAPI.IndexedDbTypes.idbObjectStore,
string,
) => WebAPI.IndexedDbTypes.idbIndex

openCursor

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. Read more on MDN

let openCursor: (
WebAPI.IndexedDbTypes.idbObjectStore,
~query: unknown=?,
~direction: WebAPI.IndexedDbTypes.idbCursorDirection=?,
) => WebAPI.IndexedDbTypes.idbRequest<Null.t<unknown>>

Parameters

~query: unknown=?
~direction: WebAPI.IndexedDbTypes.idbCursorDirection=?

Return type

WebAPI.IndexedDbTypes.idbRequest<Null.t<unknown>>

openKeyCursor

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. Read more on MDN

let openKeyCursor: (
WebAPI.IndexedDbTypes.idbObjectStore,
~query: unknown=?,
~direction: WebAPI.IndexedDbTypes.idbCursorDirection=?,
) => WebAPI.IndexedDbTypes.idbRequest<Null.t<unknown>>

Parameters

~query: unknown=?
~direction: WebAPI.IndexedDbTypes.idbCursorDirection=?

Return type

WebAPI.IndexedDbTypes.idbRequest<Null.t<unknown>>

put

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. Read more on MDN

let put: (
WebAPI.IndexedDbTypes.idbObjectStore,
~value: JSON.t,
~key: WebAPI.IndexedDbTypes.idbValidKey=?,
) => WebAPI.IndexedDbTypes.idbRequest<
WebAPI.IndexedDbTypes.idbValidKey,
>

Parameters

~value: JSON.t
~key: WebAPI.IndexedDbTypes.idbValidKey=?

Return type

WebAPI.IndexedDbTypes.idbRequest<WebAPI.IndexedDbTypes.idbValidKey>