use crate::database::{AnyPool, BackendType, Database};
pub mod context;
pub mod cron_execution;
pub mod cron_schedule;
pub mod execution_event;
pub mod models;
pub mod pipeline_execution;
pub mod recovery_event;
pub mod task_execution;
pub mod task_execution_metadata;
pub mod task_outbox;
pub mod trigger_execution;
pub mod trigger_schedule;
pub mod workflow_packages;
pub mod workflow_registry;
pub mod workflow_registry_storage;
pub use context::ContextDAL;
pub use cron_execution::CronExecutionDAL;
pub use cron_schedule::CronScheduleDAL;
pub use execution_event::ExecutionEventDAL;
pub use pipeline_execution::PipelineExecutionDAL;
pub use recovery_event::RecoveryEventDAL;
pub use task_execution::{ClaimResult, RetryStats, TaskExecutionDAL};
pub use task_execution_metadata::TaskExecutionMetadataDAL;
pub use task_outbox::TaskOutboxDAL;
pub use trigger_execution::TriggerExecutionDAL;
pub use trigger_schedule::TriggerScheduleDAL;
pub use workflow_packages::WorkflowPackagesDAL;
pub use workflow_registry::WorkflowRegistryDAL;
pub use workflow_registry_storage::UnifiedRegistryStorage;
#[macro_export]
macro_rules! backend_dispatch {
($backend:expr, $pg_block:block, $sqlite_block:block) => {{
#[cfg(all(feature = "postgres", feature = "sqlite"))]
{
match $backend {
$crate::database::BackendType::Postgres => $pg_block,
$crate::database::BackendType::Sqlite => $sqlite_block,
}
}
#[cfg(all(feature = "postgres", not(feature = "sqlite")))]
{
let _ = $backend;
$pg_block
}
#[cfg(all(feature = "sqlite", not(feature = "postgres")))]
{
let _ = $backend;
$sqlite_block
}
}};
}
#[macro_export]
macro_rules! connection_match {
($conn:expr, $pg_var:ident => $pg_block:block, $sqlite_var:ident => $sqlite_block:block) => {{
#[cfg(all(feature = "postgres", feature = "sqlite"))]
{
match $conn {
$crate::database::AnyConnection::Postgres($pg_var) => $pg_block,
$crate::database::AnyConnection::Sqlite($sqlite_var) => $sqlite_block,
}
}
#[cfg(all(feature = "postgres", not(feature = "sqlite")))]
{
let $pg_var = $conn;
$pg_block
}
#[cfg(all(feature = "sqlite", not(feature = "postgres")))]
{
let $sqlite_var = $conn;
$sqlite_block
}
}};
}
#[derive(Clone, Debug)]
pub struct DAL {
pub database: Database,
}
impl DAL {
pub fn new(database: Database) -> Self {
DAL { database }
}
pub fn backend(&self) -> BackendType {
self.database.backend()
}
pub fn database(&self) -> &Database {
&self.database
}
pub fn pool(&self) -> AnyPool {
self.database.pool()
}
pub fn context(&self) -> ContextDAL<'_> {
ContextDAL::new(self)
}
pub fn pipeline_execution(&self) -> PipelineExecutionDAL<'_> {
PipelineExecutionDAL::new(self)
}
pub fn task_execution(&self) -> TaskExecutionDAL<'_> {
TaskExecutionDAL::new(self)
}
pub fn task_execution_metadata(&self) -> TaskExecutionMetadataDAL<'_> {
TaskExecutionMetadataDAL::new(self)
}
pub fn task_outbox(&self) -> TaskOutboxDAL<'_> {
TaskOutboxDAL::new(self)
}
pub fn recovery_event(&self) -> RecoveryEventDAL<'_> {
RecoveryEventDAL::new(self)
}
pub fn execution_event(&self) -> ExecutionEventDAL<'_> {
ExecutionEventDAL::new(self)
}
pub fn cron_schedule(&self) -> CronScheduleDAL<'_> {
CronScheduleDAL::new(self)
}
pub fn cron_execution(&self) -> CronExecutionDAL<'_> {
CronExecutionDAL::new(self)
}
pub fn trigger_schedule(&self) -> TriggerScheduleDAL<'_> {
TriggerScheduleDAL::new(self)
}
pub fn trigger_execution(&self) -> TriggerExecutionDAL<'_> {
TriggerExecutionDAL::new(self)
}
pub fn workflow_packages(&self) -> WorkflowPackagesDAL<'_> {
WorkflowPackagesDAL::new(self)
}
pub fn workflow_registry<S: crate::registry::traits::RegistryStorage + 'static>(
&self,
storage: S,
) -> crate::registry::workflow_registry::WorkflowRegistryImpl<S> {
self.try_workflow_registry(storage)
.expect("Failed to create workflow registry")
}
pub fn try_workflow_registry<S: crate::registry::traits::RegistryStorage + 'static>(
&self,
storage: S,
) -> Result<
crate::registry::workflow_registry::WorkflowRegistryImpl<S>,
crate::registry::error::RegistryError,
> {
crate::registry::workflow_registry::WorkflowRegistryImpl::new(
storage,
self.database.clone(),
)
}
}