mod bootstrap;
use boson_backend_sql_common::SqlQueueBackend;
use boson_core::Result;
use sqlx::PgPool;
pub use bootstrap::{
install_default_postgres_backend, install_isolated_postgres_backend, postgres_test_url,
};
pub struct PostgresQueueBackend {
inner: SqlQueueBackend,
}
impl PostgresQueueBackend {
pub async fn new(url: &str) -> Result<Self> {
Self::connect(url).await
}
pub async fn connect(url: &str) -> Result<Self> {
let inner = SqlQueueBackend::connect_postgres(url).await?;
Ok(Self { inner })
}
pub async fn connect_isolated(url: &str, schema: &str) -> Result<Self> {
let inner = SqlQueueBackend::connect_postgres_isolated(url, schema).await?;
Ok(Self { inner })
}
pub async fn from_pool(pool: PgPool) -> Result<Self> {
let inner = SqlQueueBackend::from_postgres_pool(pool).await?;
Ok(Self { inner })
}
#[must_use]
pub fn pool(&self) -> &PgPool {
match self.inner.pool() {
boson_backend_sql_common::SqlPool::Postgres(pool) => pool,
boson_backend_sql_common::SqlPool::Sqlite(_) => {
panic!("postgres backend has non-postgres pool")
}
}
}
}
impl std::fmt::Debug for PostgresQueueBackend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PostgresQueueBackend").finish_non_exhaustive()
}
}
boson_backend_sql_common::delegate_queue_backend!(PostgresQueueBackend, inner);