Add store function

pull/1860/head
Tony 8 months ago
parent 4cb9d8de5e
commit 6cdaa31959
No known key found for this signature in database
GPG Key ID: 34BDD3EA27824956

@ -165,12 +165,22 @@ async fn save<R: Runtime>(app: AppHandle<R>, rid: ResourceId) -> Result<()> {
} }
pub trait StoreExt<R: Runtime> { pub trait StoreExt<R: Runtime> {
/// Create a store or get an existing store with default settings at path
fn store(&self, path: impl AsRef<Path>) -> Arc<Store<R>>;
/// Create a store with default settings
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>>; fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>>;
/// Get a store builder
fn store_builder(&self, path: impl AsRef<Path>) -> StoreBuilder<R>; fn store_builder(&self, path: impl AsRef<Path>) -> StoreBuilder<R>;
/// Get an existing store
fn get_store(&self, path: impl AsRef<Path>) -> Option<Arc<Store<R>>>; fn get_store(&self, path: impl AsRef<Path>) -> Option<Arc<Store<R>>>;
} }
impl<R: Runtime, T: Manager<R>> StoreExt<R> for T { impl<R: Runtime, T: Manager<R>> StoreExt<R> for T {
fn store(&self, path: impl AsRef<Path>) -> Arc<Store<R>> {
self.create_store(&path)
.unwrap_or_else(|_| self.get_store(path).unwrap())
}
fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> { fn create_store(&self, path: impl AsRef<Path>) -> Result<Arc<Store<R>>> {
StoreBuilder::new(self.app_handle(), path).build() StoreBuilder::new(self.app_handle(), path).build()
} }

Loading…
Cancel
Save