Skip to content

IndexedDBAPI

Types

idbCursorDirection

type idbCursorDirection =
| @as("next") Next
| @as("nextunique") Nextunique
| @as("prev") Prev
| @as("prevunique") Prevunique

idbDatabase

This IndexedDB API interface provides a connection to a database; you can use an IDBDatabase object to open a transaction on your database then create, manipulate, and delete objects (data) in that database. The interface provides the only way to get and manage versions of the database. See IDBDatabase on MDN

type idbDatabase = {
name: string,
version: int,
objectStoreNames: WebAPI.Prelude.domStringList,
}

Record fields

name
string

Returns the name of the database. Read more on MDN

version
int

Returns the version of the database. Read more on MDN

objectStoreNames

Returns a list of the names of object stores in the database. Read more on MDN

idbDatabaseInfo

type idbDatabaseInfo = {
mutable name?: string,
mutable version?: int,
}

Record fields

name
option< string >
version
option< int >

idbFactory

In the following code snippet, we make a request to open a database, and include handlers for the success and error cases. For a full working example, see our To-do Notifications app (view example live.) See IDBFactory on MDN

type idbFactory = {}

idbIndex

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. See IDBIndex on MDN

type idbIndex = {
mutable name: string,
objectStore: idbObjectStore,
keyPath: string,
multiEntry: bool,
unique: bool,
}

Record fields

name
string

Returns the name of the index. Read more on MDN

objectStore

Returns the IDBObjectStore the index belongs to. Read more on MDN

keyPath
string
multiEntry
bool
unique
bool

idbIndexParameters

type idbIndexParameters = {
mutable unique?: bool,
mutable multiEntry?: bool,
}

Record fields

unique
option< bool >
multiEntry
option< bool >

idbObjectStore

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.) See IDBObjectStore on MDN

type idbObjectStore = {
mutable name: string,
keyPath: string,
indexNames: WebAPI.Prelude.domStringList,
transaction: idbTransaction,
autoIncrement: bool,
}

Record fields

name
string

Returns the name of the store. Read more on MDN

keyPath
string

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

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

idbObjectStoreParameters

type idbObjectStoreParameters = {
mutable keyPath?: Null.t<unknown>,
mutable autoIncrement?: bool,
}

Record fields

keyPath
option< Null.t< unknown > >
autoIncrement
option< bool >

idbOpenDBRequest

Also inherits methods from its parents IDBRequest and EventTarget. See IDBOpenDBRequest on MDN

type idbOpenDBRequest = {
result: idbDatabase,
error: Null.t<WebAPI.Prelude.domException>,
source: unknown,
transaction: Null.t<idbTransaction>,
readyState: idbRequestReadyState,
}

Record fields

result

When a request is completed, returns the result, or undefined if the request failed. Throws a "InvalidStateError" DOMException if the request is still pending. Read more on MDN

error

When a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws a "InvalidStateError" DOMException if the request is still pending. Read more on MDN

source
unknown

Returns the IDBObjectStore, IDBIndex, or IDBCursor the request was made against, or null if is was an open request. Read more on MDN

transaction
Null.t< idbTransaction >

Returns the IDBTransaction the request was made within. If this as an open request, then it returns an upgrade transaction while it is running, or null otherwise. Read more on MDN

readyState

Returns "pending" until a request is complete, then returns "done". Read more on MDN

idbRequest

The request object does not initially contain any information about the result of the operation, but once information becomes available, an event is fired on the request, and the information becomes available through the properties of the IDBRequest instance. See IDBRequest on MDN

type idbRequest<'t> = {
result: 't,
error: Null.t<WebAPI.Prelude.domException>,
source: unknown,
transaction: Null.t<idbTransaction>,
readyState: idbRequestReadyState,
}

Record fields

result
't

When a request is completed, returns the result, or undefined if the request failed. Throws a "InvalidStateError" DOMException if the request is still pending. Read more on MDN

error

When a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws a "InvalidStateError" DOMException if the request is still pending. Read more on MDN

source
unknown

Returns the IDBObjectStore, IDBIndex, or IDBCursor the request was made against, or null if is was an open request. Read more on MDN

transaction
Null.t< idbTransaction >

Returns the IDBTransaction the request was made within. If this as an open request, then it returns an upgrade transaction while it is running, or null otherwise. Read more on MDN

readyState

Returns "pending" until a request is complete, then returns "done". Read more on MDN

idbRequestReadyState

type idbRequestReadyState =
| @as("done") Done
| @as("pending") Pending

idbTransaction

type idbTransaction = {
objectStoreNames: WebAPI.Prelude.domStringList,
mode: idbTransactionMode,
durability: idbTransactionDurability,
db: idbDatabase,
error: Null.t<WebAPI.Prelude.domException>,
}

Record fields

objectStoreNames

Returns a list of the names of object stores in the transaction's scope. For an upgrade transaction this is all object stores in the database. Read more on MDN

mode

Returns the mode the transaction was created with ("readonly" or "readwrite"), or "versionchange" for an upgrade transaction. Read more on MDN

db

Returns the transaction's connection. Read more on MDN

error

If the transaction was aborted, returns the error (a DOMException) providing the reason. Read more on MDN

idbTransactionDurability

type idbTransactionDurability =
| @as("default") Default
| @as("relaxed") Relaxed
| @as("strict") Strict

idbTransactionMode

type idbTransactionMode =
| @as("readonly") Readonly
| @as("readwrite") Readwrite
| @as("versionchange") Versionchange

idbTransactionOptions

type idbTransactionOptions = {
mutable durability?: idbTransactionDurability,
}

Record fields

durability

idbValidKey

type idbValidKey = WebAPI.Prelude.any