idb

Types

Type to represent a connection to an IndexedDB database.

Use connect to create an instance of Connection.

pub type Connection

Type to represent an IndexedDB error.

pub type IdbError

Type to represent an IndexedDB index.

Use create_index to create an instance of Index.

pub type Index

Type to represent the key used on an IndexedDB object store or index.

pub type Key =
  @internal Key

Type to represent an IndexedDB object store.

Use create_store to create an instance of ObjectStore.

pub type ObjectStore

Type to represent an IndexedDB transaction.

Use start_transaction to create an instance of Transaction.

pub type Transaction =
  @internal Transaction

Type to represent an IndexedDB transaction access mode.

pub type TransactionMode {
  ReadOnly
  ReadWrite
}

Constructors

  • ReadOnly
  • ReadWrite

Values

pub fn add(
  store: ObjectStore,
  value: json.Json,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Inserts a new record to an object store.

The last argument is executed with the key or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.add on the IndexedDB API.

pub fn add_to(
  store: ObjectStore,
  key: Key,
  value: json.Json,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Inserts a new record using a specified key to an object store.

The last argument is executed with the key or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.add on the IndexedDB API.

pub fn connect(
  name: String,
  version: Int,
  event_handlers: List(event.ConnectEventHandler(a, b, c, d)),
  next: fn(Result(Connection, IdbError)) -> e,
) -> Nil

Creates a connection to an IndexedDB database with the specified name and version.

If the specified version is zero or negative value, then it will be treated as 1.

If the database does not exist, then it will be created.

The last argument is executed when the connection is created or when the attempt is failed. The returned value is discarded.

Similar to the IDBFactory.open on the IndexedDB API.

pub fn count(
  store: ObjectStore,
  query: range.KeyRange,
  next: fn(Result(Int, IdbError)) -> a,
) -> Nil

Retrieves the total number of records within the range in an object store.

The last argument is executed with the result or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.count on the IndexedDB API.

pub fn create_index(
  store: ObjectStore,
  name: String,
  key: index.IndexKey,
) -> Result(Index, IdbError)

Creates an index that referenced the specified object store with the specified name.

Can only be called using ObjectStore inside a versionchange transaction, will return an Error otherwise. Use connect with on_upgrade to initialize a versionchange transaction.

Similar to the IDBObjectStore.createIndex on the IndexedDB API.

pub fn create_store(
  tx: Transaction,
  name: String,
  key: store.ObjectStoreKey,
) -> Result(ObjectStore, IdbError)

Creates a new object store with the specified name and key.

Can only be called using versionchange transaction, will return an Error otherwise. Use connect with on_upgrade to initialize a versionchange transaction.

Similar to the IDBDatabase.createObjectStore on the IndexedDB API.

pub fn delete(
  store: ObjectStore,
  query: range.KeyRange,
  next: fn(Result(Nil, IdbError)) -> a,
) -> Nil

Deletes all records within the range from an object store.

The last argument is executed when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.delete and IDBObjectStore.clear on the IndexedDB API.

pub fn delete_database(
  name: String,
  next: fn(Result(Nil, IdbError)) -> a,
) -> Nil

Deletes an IndexedDB database with the specified name.

The last argument is executed when the database is deleted or when the attempt is failed. The returned value is discarded.

Similar to the IDBFactory.deleteDatabase on the IndexedDB API.

pub fn delete_index(
  store: ObjectStore,
  name: String,
) -> Result(Nil, IdbError)

Deletes an index that referenced the specified object store with the specified name.

Can only be called using ObjectStore inside a versionchange transaction, will return an Error otherwise. Use connect with on_upgrade to initialize a versionchange transaction.

Similar to the IDBObjectStore.deleteIndex on the IndexedDB API.

pub fn delete_store(
  tx: Transaction,
  name: String,
) -> Result(Nil, IdbError)

Deletes an object store with the specified name, along with any indexes that reference it.

Can only be called using versionchange transaction, will return an Error otherwise. Use connect with on_upgrade to initialize a versionchange transaction.

Similar to the IDBDatabase.deleteObjectStore on the IndexedDB API.

pub fn get(
  store: ObjectStore,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves all records within the range from an object store.

The last argument is executed with the record values or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.getAll on the IndexedDB API.

pub fn get_databases(
  next: fn(Result(List(#(String, Int)), IdbError)) -> a,
) -> Nil

Retrieves a list of available databases, returning its name and version.

The last argument is executed when the list is available or when the attempt is failed.

pub fn get_index(
  store: ObjectStore,
  name: String,
) -> Result(Index, IdbError)

Retrieves an index to be used for operations.

pub fn get_index_names(store: ObjectStore) -> List(String)

Retrieves a list of the names of the indexes currently referencing the object store.

pub fn get_keys(
  store: ObjectStore,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves all keys within the range from an object store.

The last argument is executed with the record keys or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.getAllKeys on the IndexedDB API.

pub fn get_keys_with_limit(
  store: ObjectStore,
  query: range.KeyRange,
  limit: Int,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves some keys within the range from an object store.

Limits the retrieved keys to the amount specified on the third argument. If the limit is a negative Int, then it will be treated as no limit.

The last argument is executed with the record keys or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.getAllKeys on the IndexedDB API.

pub fn get_one(
  store: ObjectStore,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves the first record within the range from an object store.

The last argument is executed with the record value or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.get on the IndexedDB API.

pub fn get_one_key(
  store: ObjectStore,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves the first key within the range from an object store.

The last argument is executed with the record key or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.getKey on the IndexedDB API.

pub fn get_store(
  tx: Transaction,
  name: String,
) -> Result(ObjectStore, IdbError)

Retrieves an object store to be used for operations.

pub fn get_store_names(db: Connection) -> List(String)

Retrieves a list of the names of the object stores currently in the connected database.

pub fn get_transaction_store_names(
  tx: Transaction,
) -> List(String)

Retrieves a list of the names of the object stores currently available in the transaction.

pub fn get_with_limit(
  store: ObjectStore,
  query: range.KeyRange,
  limit: Int,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves some records within the range from an object store.

Limits the retrieved records to the amount specified on the third argument. If the limit is a negative Int, then it will be treated as no limit.

The last argument is executed with the record values or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.getAll on the IndexedDB API.

pub fn index_count(
  index: Index,
  query: range.KeyRange,
  next: fn(Result(Int, IdbError)) -> a,
) -> Nil

Retrieves the total number of records within the range in an index.

The last argument is executed with the result or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBIndex.count on the IndexedDB API.

pub fn index_get(
  index: Index,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves all records within the range from an index.

The last argument is executed with the record values or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBIndex.getAll on the IndexedDB API.

pub fn index_get_keys(
  index: Index,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves all keys within the range from an index.

The last argument is executed with the index keys or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBIndex.getAllKeys on the IndexedDB API.

pub fn index_get_keys_with_limit(
  index: Index,
  query: range.KeyRange,
  limit: Int,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves some keys within the range from an index.

Limits the retrieved keys to the amount specified on the third argument. If the limit is a negative Int, then it will be treated as no limit.

The last argument is executed with the index keys or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBIndex.getAllKeys on the IndexedDB API.

pub fn index_get_one(
  index: Index,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves the first record within the range from an index.

The last argument is executed with the record value or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBIndex.get on the IndexedDB API.

pub fn index_get_one_key(
  index: Index,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves the first key within the range from an index.

The last argument is executed with the index key or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBIndex.getKey on the IndexedDB API.

pub fn index_get_with_limit(
  index: Index,
  query: range.KeyRange,
  limit: Int,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves some records within the range from an index.

Limits the retrieved records to the amount specified on the third argument. If the limit is a negative Int, then it will be treated as no limit.

The last argument is executed with the record values or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBIndex.getAll on the IndexedDB API.

pub fn key_float(value: Float) -> Key

Creates a new Key from Float.

pub fn key_int(value: Int) -> Key

Creates a new Key from Int.

pub fn key_list(value: List(Key)) -> Key

Creates a new Key from a list of Key.

pub fn key_string(value: String) -> Key

Creates a new Key from String.

pub fn put(
  store: ObjectStore,
  value: json.Json,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Updates a record in an object store or inserts a new record if it does not already exist.

The last argument is executed with the key or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.put on the IndexedDB API.

pub fn put_to(
  store: ObjectStore,
  key: Key,
  value: json.Json,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Updates a record using a specified key in an object store or inserts a new record if it does not already exist.

The last argument is executed with the key or an error when the operation is completed or errored. The returned value is discarded.

Similar to the IDBObjectStore.put on the IndexedDB API.

pub fn quick_add(
  db: Connection,
  store_name: String,
  value: json.Json,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Inserts a new record to an object store inside a new transaction.

The last argument is executed with the key or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with add.

pub fn quick_add_to(
  db: Connection,
  store_name: String,
  key: Key,
  value: json.Json,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Inserts a new record using a specified key to an object store inside a new transaction.

The last argument is executed with the key or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with add_to.

pub fn quick_count(
  db: Connection,
  store_name: String,
  query: range.KeyRange,
  next: fn(Result(Int, IdbError)) -> a,
) -> Nil

Retrieves the total number of records within the range in an object store inside a new transaction.

The last argument is executed with the result or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with count.

pub fn quick_delete(
  db: Connection,
  store_name: String,
  query: range.KeyRange,
  next: fn(Result(Nil, IdbError)) -> a,
) -> Nil

Deletes all records within the range from an object store inside a new transaction.

The last argument is executed when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with delete.

pub fn quick_get(
  db: Connection,
  store_name: String,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves all records within the range from an object store inside a new transaction.

The last argument is executed with the record values or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with get.

pub fn quick_get_keys(
  db: Connection,
  store_name: String,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves all keys within the range from an object store inside a new transaction.

The last argument is executed with the record keys or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with get_keys.

pub fn quick_get_keys_with_limit(
  db: Connection,
  store_name: String,
  query: range.KeyRange,
  limit: Int,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves some keys within the range from an object store inside a new transaction.

Limits the retrieved keys to the amount specified on the fourth argument. If the limit is a negative Int, then it will be treated as no limit.

The last argument is executed with the record keys or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with get_keys_with_limit.

pub fn quick_get_one(
  db: Connection,
  store_name: String,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves the first record within the range from an object store inside a new transaction.

The last argument is executed with the record value or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with get_one.

pub fn quick_get_one_key(
  db: Connection,
  store_name: String,
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves the first key within the range from an object store inside a new transaction.

The last argument is executed with the record key or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with get_one_key.

pub fn quick_get_with_limit(
  db: Connection,
  store_name: String,
  query: range.KeyRange,
  limit: Int,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves some records within the range from an object store inside a new transaction.

Limits the retrieved records to the amount specified on the fourth argument. If the limit is a negative Int, then it will be treated as no limit.

The last argument is executed with the record values or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with get_with_limit.

pub fn quick_index_count(
  db: Connection,
  store_index_name: #(String, String),
  query: range.KeyRange,
  next: fn(Result(Int, IdbError)) -> a,
) -> Nil

Retrieves the total number of records within the range in an index inside a new transaction.

The last argument is executed with the result or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_index_transaction with index_count.

pub fn quick_index_get(
  db: Connection,
  store_index_name: #(String, String),
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves all records within the range from an index inside a new transaction.

The last argument is executed with the record values or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_index_transaction with index_get.

pub fn quick_index_get_keys(
  db: Connection,
  store_index_name: #(String, String),
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves all keys within the range from an index inside a new transaction.

The last argument is executed with the index keys or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_index_transaction with index_get_keys.

pub fn quick_index_get_keys_with_limit(
  db: Connection,
  store_index_name: #(String, String),
  query: range.KeyRange,
  limit: Int,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves some keys within the range from an index inside a new transaction.

Limits the retrieved keys to the amount specified on the fourth argument. If the limit is a negative Int, then it will be treated as no limit.

The last argument is executed with the index keys or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_index_transaction with index_get_keys_with_limit.

pub fn quick_index_get_one(
  db: Connection,
  store_index_name: #(String, String),
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves the first record within the range from an index inside a new transaction.

The last argument is executed with the record value or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_index_transaction with index_get_one.

pub fn quick_index_get_one_key(
  db: Connection,
  store_index_name: #(String, String),
  query: range.KeyRange,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves the first key within the range from an index inside a new transaction.

The last argument is executed with the index key or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_index_transaction with index_get_one_key.

pub fn quick_index_get_with_limit(
  db: Connection,
  store_index_name: #(String, String),
  query: range.KeyRange,
  limit: Int,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Retrieves some records within the range from an index inside a new transaction.

Limits the retrieved records to the amount specified on the fourth argument. If the limit is a negative Int, then it will be treated as no limit.

The last argument is executed with the record values or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_index_transaction with index_get_with_limit.

pub fn quick_put(
  db: Connection,
  store_name: String,
  value: json.Json,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Updates a record in an object store or inserts a new record if it does not already exist inside a new transaction.

The last argument is executed with the key or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with put.

pub fn quick_put_to(
  db: Connection,
  store_name: String,
  key: Key,
  value: json.Json,
  next: fn(Result(dynamic.Dynamic, IdbError)) -> a,
) -> Nil

Updates a record using a specified key in an object store or inserts a new record if it does not already exist inside a new transaction.

The last argument is executed with the key or an error when the operation is completed or errored. The returned value is discarded.

This is an utility function that combines start_store_transaction with put_to.

pub fn start_index_transaction(
  db: Connection,
  store_index_name: #(String, String),
  on_close: fn(Result(Nil, IdbError)) -> a,
) -> Result(Index, IdbError)

Starts a new transaction with only a single index.

The last argument is executed when the transaction is completed or errored. The returned value is discarded.

This is an utility function that combines start_transaction with get_store and get_index.

pub fn start_store_transaction(
  db: Connection,
  store_name: String,
  mode: TransactionMode,
  on_close: fn(Result(Nil, IdbError)) -> a,
) -> Result(ObjectStore, IdbError)

Starts a new transaction with only a single object store.

The last argument is executed when the transaction is completed or errored. The returned value is discarded.

This is an utility function that combines start_transaction with get_store.

pub fn start_transaction(
  db: Connection,
  store_names: List(String),
  mode: TransactionMode,
  on_close: fn(Result(Nil, IdbError)) -> a,
) -> Result(Transaction, IdbError)

Starts a new transaction that can be used to access the specified object stores.

The last argument is executed when the transaction is completed or errored. The returned value is discarded.

Similar to the IDBDatabase.transaction on the IndexedDB API.

pub fn try_connect(
  name: String,
  version: Int,
  event_handlers: List(event.ConnectEventHandler(a, b, c, d)),
  apply fun: fn(Connection) -> Result(e, IdbError),
) -> Nil

This is an utility function that combines connect with result.try.

Search Document