miden_client_sqlite_store/
builder.rs1use std::path::PathBuf;
2use std::sync::Arc;
3
4use miden_client::builder::{BuilderAuthenticator, ClientBuilder, StoreBuilder, StoreFactory};
5use miden_client::store::{Store, StoreError};
6
7use crate::SqliteStore;
8
9pub trait ClientBuilderSqliteExt<AUTH> {
11 fn sqlite_store(self, database_filepath: PathBuf) -> ClientBuilder<AUTH>;
12}
13
14impl<AUTH: BuilderAuthenticator> ClientBuilderSqliteExt<AUTH> for ClientBuilder<AUTH> {
15 fn sqlite_store(mut self, database_filepath: PathBuf) -> ClientBuilder<AUTH> {
18 self.store =
19 Some(StoreBuilder::Factory(Box::new(SqliteStoreFactory { database_filepath })));
20 self
21 }
22}
23
24struct SqliteStoreFactory {
26 database_filepath: PathBuf,
27}
28
29#[async_trait::async_trait]
30impl StoreFactory for SqliteStoreFactory {
31 async fn build(&self) -> Result<Arc<dyn Store>, StoreError> {
32 let sqlite_store = SqliteStore::new(self.database_filepath.clone()).await?;
33 Ok(Arc::new(sqlite_store))
34 }
35}