use crate::store::TransactionalStoreFactory;
#[cfg(any(
feature = "batch-store",
feature = "location",
feature = "pike",
feature = "product",
feature = "purchase-order",
feature = "schema",
feature = "track-and-trace",
))]
use std::sync::Arc;
#[cfg(feature = "diesel")]
use diesel::r2d2::{ConnectionManager, Pool};
#[cfg(feature = "postgres")]
use crate::store::postgres::PgStoreFactory;
#[cfg(feature = "sqlite")]
use crate::store::sqlite::SqliteStoreFactory;
#[derive(Clone)]
pub struct StoreState {
pub store_factory: Arc<dyn TransactionalStoreFactory>,
}
#[allow(clippy::redundant_clone)]
#[allow(unused_variables)]
#[cfg(feature = "postgres")]
impl StoreState {
pub fn with_pg_pool(
connection_pool: Pool<ConnectionManager<diesel::pg::PgConnection>>,
) -> Self {
Self {
store_factory: Arc::new(PgStoreFactory::new(connection_pool)),
}
}
#[cfg(feature = "sqlite")]
pub fn with_sqlite_pool(
connection_pool: Pool<ConnectionManager<diesel::sqlite::SqliteConnection>>,
) -> Self {
Self {
store_factory: Arc::new(SqliteStoreFactory::new(connection_pool)),
}
}
}