plinth/browser/indexeddb/database
Types
pub type Durability {
Strict
Relaxed
Default
}
Constructors
-
Strict -
Relaxed -
Default
Values
pub fn create_object_store(
database: Database,
name: String,
key_path: option.Option(String),
auto_increment: Bool,
) -> Result(object_store.ObjectStore, String)
This method can be called only within a versionchange transaction.
In-Line Out-Of-Line keys
https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB#structuring_the_database
IndexedDB has two ways to handle keys: In-line keys: The key is a property within the stored object itself { id: 1, name: “Alice”, email: “alice@example.com” }
Out-of-line keys: The key is stored separately and is not part of the object { name: “Alice”, email: “alice@example.com” }
If a key_path is provided then in-line keys are used. Storing simple values, not objects, will require out-of-line keys
Autoincrement and key_path can be used in any combination, though use of the database is affected
If auto_increment is False and you store a value without an id you will get an error.
Key vs Index
The key, in-line or out-of-line, is automatically indexed and unique.
Using add will fail if inserting a value with a key that already exists.
Use put to insert or replace a value
pub fn object_store_names(
database: Database,
) -> array.Array(String)
pub fn transaction(
database: Database,
store_names: List(String),
mode: Mode,
durability: Durability,
) -> Result(transaction.Transaction, String)