mod bootstrap;
use chronon_backend_sql_common::SqlSchedulerStore;
use chronon_core::Result;
use sqlx::PgPool;
pub use bootstrap::{postgres_store_from_env, postgres_test_url};
pub struct PostgresSchedulerStore {
inner: SqlSchedulerStore,
}
impl PostgresSchedulerStore {
pub async fn connect(url: &str) -> Result<Self> {
let inner = SqlSchedulerStore::connect_postgres(url).await?;
Ok(Self { inner })
}
pub async fn connect_isolated(url: &str, schema: &str) -> Result<Self> {
let inner = SqlSchedulerStore::connect_postgres_isolated(url, schema).await?;
Ok(Self { inner })
}
pub async fn attach_isolated(url: &str, schema: &str) -> Result<Self> {
let inner = SqlSchedulerStore::attach_postgres_isolated(url, schema).await?;
Ok(Self { inner })
}
pub async fn drop_isolated_schema(url: &str, schema: &str) -> Result<()> {
SqlSchedulerStore::drop_postgres_schema(url, schema).await
}
pub async fn from_pool(pool: PgPool) -> Result<Self> {
let inner = SqlSchedulerStore::from_postgres_pool(pool).await?;
Ok(Self { inner })
}
#[must_use]
pub fn pool(&self) -> &PgPool {
match self.inner.pool() {
chronon_backend_sql_common::SqlPool::Postgres(pool) => pool,
chronon_backend_sql_common::SqlPool::Sqlite(_) => {
panic!("postgres backend has non-postgres pool")
}
}
}
}
impl std::fmt::Debug for PostgresSchedulerStore {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PostgresSchedulerStore")
.finish_non_exhaustive()
}
}
chronon_backend_sql_common::delegate_scheduler_store!(PostgresSchedulerStore, inner);