pub struct ObjectStore<Err> { /* private fields */ }
Expand description
Wrapper for IDBObjectStore
,
for use in transactions
Implementations§
Source§impl<Err> ObjectStore<Err>
impl<Err> ObjectStore<Err>
Sourcepub fn build_index<'a>(
&self,
name: &'a str,
key_path: &str,
) -> IndexBuilder<'a, Err>
pub fn build_index<'a>( &self, name: &'a str, key_path: &str, ) -> IndexBuilder<'a, Err>
Build an index over this object store
Note that this method can only be called from within an on_upgrade_needed
callback. It returns
a builder, and calling the create
method on this builder will perform the actual creation.
If you want to make an index that searches multiple columns, please use ObjectStore::build_compound_index
.
Internally, this uses IDBObjectStore::createIndex
.
Sourcepub fn build_compound_index<'a>(
&self,
name: &'a str,
key_paths: &[&str],
) -> IndexBuilder<'a, Err>
pub fn build_compound_index<'a>( &self, name: &'a str, key_paths: &[&str], ) -> IndexBuilder<'a, Err>
Build a compound index over this object store
Note that this method can only be called from within an on_upgrade_needed
callback. It returns
a builder, and calling the create
method on this builder will perform the actual creation.
Interesting points about indices:
- It is not possible to index
bool
in IndexedDB. - If your index uses a column that does not exist, then the object will not be recorded in the index.
This is useful for unique compound indices, usually when you would have conditionally indexed a
bool
column otherwise. - You cannot build a compound multi-entry index, it needs to be a regular index.
Internally, this uses IDBObjectStore::createIndex
.
Sourcepub fn delete_index(&self, name: &str) -> Result<(), Err>
pub fn delete_index(&self, name: &str) -> Result<(), Err>
Delete an index from this object store
Note that this method can only be called from within an on_upgrade_needed
callback.
Internally, this uses IDBObjectStore::deleteIndex
.
Sourcepub fn add(&self, value: &JsValue) -> impl Future<Output = Result<JsValue, Err>>
pub fn add(&self, value: &JsValue) -> impl Future<Output = Result<JsValue, Err>>
Add the value value
to this object store, and return its auto-computed key
This will error if the key already existed.
Internally, this uses IDBObjectStore::add
.
Sourcepub fn add_kv(
&self,
key: &JsValue,
value: &JsValue,
) -> impl Future<Output = Result<(), Err>>
pub fn add_kv( &self, key: &JsValue, value: &JsValue, ) -> impl Future<Output = Result<(), Err>>
Add the value value
to this object store, with key key
This will error if the key already existed.
Internally, this uses IDBObjectStore::add
.
Sourcepub fn put(&self, value: &JsValue) -> impl Future<Output = Result<JsValue, Err>>
pub fn put(&self, value: &JsValue) -> impl Future<Output = Result<JsValue, Err>>
Add the value value
to this object store, and return its auto-computed key
This will overwrite the previous value if the key already existed.
Internally, this uses IDBObjectStore::add
.
Sourcepub fn put_kv(
&self,
key: &JsValue,
value: &JsValue,
) -> impl Future<Output = Result<(), Err>>
pub fn put_kv( &self, key: &JsValue, value: &JsValue, ) -> impl Future<Output = Result<(), Err>>
Add the value value
to this object store, with key key
This will overwrite the previous value if the key already existed.
Internally, this uses IDBObjectStore::add
.
Sourcepub fn clear(&self) -> impl Future<Output = Result<(), Err>>
pub fn clear(&self) -> impl Future<Output = Result<(), Err>>
Clear this object store
Internally, this uses IDBObjectStore::clear
.
Sourcepub fn count(&self) -> impl Future<Output = Result<usize, Err>>
pub fn count(&self) -> impl Future<Output = Result<usize, Err>>
Count the number of objects in this store
Internally, this uses IDBObjectStore::count
.
Sourcepub fn contains(&self, key: &JsValue) -> impl Future<Output = Result<bool, Err>>
pub fn contains(&self, key: &JsValue) -> impl Future<Output = Result<bool, Err>>
Checks whether the provided key exists in this object store
Internally, this uses IDBObjectStore::count
.
Sourcepub fn count_in(
&self,
range: impl RangeBounds<JsValue>,
) -> impl Future<Output = Result<usize, Err>>
pub fn count_in( &self, range: impl RangeBounds<JsValue>, ) -> impl Future<Output = Result<usize, Err>>
Counts the number of objects with a key in range
Note that the unbounded range is not a valid range for IndexedDB.
Internally, this uses IDBObjectStore::count
.
Sourcepub fn delete(&self, key: &JsValue) -> impl Future<Output = Result<(), Err>>
pub fn delete(&self, key: &JsValue) -> impl Future<Output = Result<(), Err>>
Delete the object with key key
Unfortunately, the IndexedDb API does not indicate whether an object was actually deleted.
Internally, this uses IDBObjectStore::delete
.
Sourcepub fn delete_range(
&self,
range: impl RangeBounds<JsValue>,
) -> impl Future<Output = Result<(), Err>>
pub fn delete_range( &self, range: impl RangeBounds<JsValue>, ) -> impl Future<Output = Result<(), Err>>
Delete all the objects with a key in range
Note that the unbounded range is not a valid range for IndexedDB. Unfortunately, the IndexedDb API does not indicate whether an object was actually deleted.
Internally, this uses IDBObjectStore::delete
.
Sourcepub fn get(
&self,
key: &JsValue,
) -> impl Future<Output = Result<Option<JsValue>, Err>>
pub fn get( &self, key: &JsValue, ) -> impl Future<Output = Result<Option<JsValue>, Err>>
Get the object with key key
Internally, this uses IDBObjectStore::get
.
Sourcepub fn get_first_in(
&self,
range: impl RangeBounds<JsValue>,
) -> impl Future<Output = Result<Option<JsValue>, Err>>
pub fn get_first_in( &self, range: impl RangeBounds<JsValue>, ) -> impl Future<Output = Result<Option<JsValue>, Err>>
Get the first value with a key in range
, ordered by key
Note that the unbounded range is not a valid range for IndexedDB.
Internally, this uses IDBObjectStore::get
.
Sourcepub fn get_all(
&self,
limit: Option<u32>,
) -> impl Future<Output = Result<Vec<JsValue>, Err>>
pub fn get_all( &self, limit: Option<u32>, ) -> impl Future<Output = Result<Vec<JsValue>, Err>>
Get all the objects in the store, with a maximum number of results of limit
Internally, this uses IDBObjectStore::getAll
.
Sourcepub fn get_all_in(
&self,
range: impl RangeBounds<JsValue>,
limit: Option<u32>,
) -> impl Future<Output = Result<Vec<JsValue>, Err>>
pub fn get_all_in( &self, range: impl RangeBounds<JsValue>, limit: Option<u32>, ) -> impl Future<Output = Result<Vec<JsValue>, Err>>
Get all the objects with a key in the provided range, with a maximum number of results of limit
Internally, this uses IDBObjectStore::getAll
.
Sourcepub fn get_first_key_in(
&self,
range: impl RangeBounds<JsValue>,
) -> impl Future<Output = Result<Option<JsValue>, Err>>
pub fn get_first_key_in( &self, range: impl RangeBounds<JsValue>, ) -> impl Future<Output = Result<Option<JsValue>, Err>>
Get the first existing key in the provided range
Internally, this uses IDBObjectStore::getKey
.
Sourcepub fn get_all_keys(
&self,
limit: Option<u32>,
) -> impl Future<Output = Result<Vec<JsValue>, Err>>
pub fn get_all_keys( &self, limit: Option<u32>, ) -> impl Future<Output = Result<Vec<JsValue>, Err>>
List all the keys in the object store, with a maximum number of results of limit
Internally, this uses IDBObjectStore::getAllKeys
.
Sourcepub fn get_all_keys_in(
&self,
range: impl RangeBounds<JsValue>,
limit: Option<u32>,
) -> impl Future<Output = Result<Vec<JsValue>, Err>>
pub fn get_all_keys_in( &self, range: impl RangeBounds<JsValue>, limit: Option<u32>, ) -> impl Future<Output = Result<Vec<JsValue>, Err>>
List all the keys in the provided range, with a maximum number of results of limit
Internally, this uses IDBObjectStore::getAllKeys
.
Sourcepub fn index(&self, name: &str) -> Result<Index<Err>, Err>
pub fn index(&self, name: &str) -> Result<Index<Err>, Err>
Get the Index
with the provided name
Internally, this uses IDBObjectStore::index
.
Sourcepub fn cursor(&self) -> CursorBuilder<Err>
pub fn cursor(&self) -> CursorBuilder<Err>
Open a Cursor
on this object store