Struct ObjectStore

Source
pub struct ObjectStore<Err> { /* private fields */ }
Expand description

Wrapper for IDBObjectStore, for use in transactions

Implementations§

Source§

impl<Err> ObjectStore<Err>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn clear(&self) -> impl Future<Output = Result<(), Err>>

Clear this object store

Internally, this uses IDBObjectStore::clear.

Source

pub fn count(&self) -> impl Future<Output = Result<usize, Err>>

Count the number of objects in this store

Internally, this uses IDBObjectStore::count.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get( &self, key: &JsValue, ) -> impl Future<Output = Result<Option<JsValue>, Err>>

Get the object with key key

Internally, this uses IDBObjectStore::get.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn index(&self, name: &str) -> Result<Index<Err>, Err>

Get the Index with the provided name

Internally, this uses IDBObjectStore::index.

Source

pub fn cursor(&self) -> CursorBuilder<Err>

Open a Cursor on this object store

Trait Implementations§

Source§

impl<Err: Debug> Debug for ObjectStore<Err>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Err> Freeze for ObjectStore<Err>

§

impl<Err> RefUnwindSafe for ObjectStore<Err>
where Err: RefUnwindSafe,

§

impl<Err> !Send for ObjectStore<Err>

§

impl<Err> !Sync for ObjectStore<Err>

§

impl<Err> Unpin for ObjectStore<Err>
where Err: Unpin,

§

impl<Err> UnwindSafe for ObjectStore<Err>
where Err: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.