use std::path::Path;
use chronon_backend_sql_common::SqlSchedulerStore;
use chronon_core::Result;
use sqlx::SqlitePool;
pub struct SqliteSchedulerStore {
inner: SqlSchedulerStore,
}
impl SqliteSchedulerStore {
pub async fn new(path: impl AsRef<Path>) -> Result<Self> {
let url = format!("sqlite://{}?mode=rwc", path.as_ref().display());
Self::connect(&url).await
}
pub async fn connect(url: &str) -> Result<Self> {
let inner = SqlSchedulerStore::connect_sqlite(url).await?;
Ok(Self { inner })
}
pub async fn from_pool(pool: SqlitePool) -> Result<Self> {
let inner = SqlSchedulerStore::from_sqlite_pool(pool).await?;
Ok(Self { inner })
}
#[must_use]
pub fn pool(&self) -> &SqlitePool {
match self.inner.pool() {
chronon_backend_sql_common::SqlPool::Sqlite(pool) => pool,
chronon_backend_sql_common::SqlPool::Postgres(_) => {
panic!("sqlite backend has non-sqlite pool")
}
}
}
}
impl std::fmt::Debug for SqliteSchedulerStore {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SqliteSchedulerStore")
.finish_non_exhaustive()
}
}
chronon_backend_sql_common::delegate_scheduler_store!(SqliteSchedulerStore, inner);