pub mod error;
pub mod handle;
pub mod migrations;
pub mod repo;
pub mod schema;
pub mod transaction;
pub mod types;
pub use error::DbError;
pub use handle::DbHandle;
pub use transaction::DbTransaction;
pub use types::{
ArtifactRecord, BudgetCheckpoint, DecisionRecord, EventRecord, GoalFilter, GoalRecord,
GoalSummary, ProofRecord, TaskRecord,
};
pub use repo::{
artifact::ArtifactRepo,
budget::BudgetRepo,
decision::DecisionRepo,
event::EventRepo,
goal::GoalRepo,
proof::ProofRepo,
slice_lease::{SliceLease, SliceLeaseRepo},
task::TaskRepo,
};
use repo::{
artifact::ArtifactRepoImpl, budget::BudgetRepoImpl, decision::DecisionRepoImpl,
event::EventRepoImpl, goal::GoalRepoImpl, proof::ProofRepoImpl,
slice_lease::SliceLeaseRepoImpl, task::TaskRepoImpl,
};
use std::sync::OnceLock;
static GLOBAL_DB: OnceLock<DbHandle> = OnceLock::new();
pub fn set_global_db(db: DbHandle) -> Result<(), DbHandle> {
GLOBAL_DB.set(db)
}
pub fn global_db() -> Option<DbHandle> {
GLOBAL_DB.get().cloned()
}
impl DbHandle {
pub fn goal_repo(&self) -> GoalRepoImpl {
GoalRepoImpl {
conn: self.conn.clone(),
}
}
pub fn task_repo(&self) -> TaskRepoImpl {
TaskRepoImpl {
conn: self.conn.clone(),
}
}
pub fn event_repo(&self) -> EventRepoImpl {
EventRepoImpl {
conn: self.conn.clone(),
}
}
pub fn proof_repo(&self) -> ProofRepoImpl {
ProofRepoImpl {
conn: self.conn.clone(),
}
}
pub fn budget_repo(&self) -> BudgetRepoImpl {
BudgetRepoImpl {
conn: self.conn.clone(),
}
}
pub fn artifact_repo(&self) -> ArtifactRepoImpl {
ArtifactRepoImpl {
conn: self.conn.clone(),
}
}
pub fn decision_repo(&self) -> DecisionRepoImpl {
DecisionRepoImpl {
conn: self.conn.clone(),
}
}
pub fn slice_lease_repo(&self) -> SliceLeaseRepoImpl {
SliceLeaseRepoImpl {
conn: self.conn.clone(),
}
}
}
#[cfg(test)]
mod tests;