pub struct Database { /* private fields */ }Expand description
Database connection wrapper with health-aware replica routing and workload isolation.
Implementations§
Source§impl Database
impl Database
Sourcepub async fn from_config(config: &DatabaseConfig) -> Result<Self>
pub async fn from_config(config: &DatabaseConfig) -> Result<Self>
Create a new database connection from configuration.
Sourcepub async fn from_config_with_service(
config: &DatabaseConfig,
service_name: &str,
) -> Result<Self>
pub async fn from_config_with_service( config: &DatabaseConfig, service_name: &str, ) -> Result<Self>
Create a new database connection with a service name for tracing.
The service name is set as PostgreSQL’s application_name, visible in
pg_stat_activity for correlating queries to the originating service.
Sourcepub fn read_pool(&self) -> &PgPool
pub fn read_pool(&self) -> &PgPool
Get a pool for reads. Skips unhealthy replicas, falls back to primary.
Sourcepub fn jobs_pool(&self) -> &PgPool
pub fn jobs_pool(&self) -> &PgPool
Pool for background jobs, cron, daemons, and workflows. Falls back to primary if no isolated pool is configured.
Sourcepub fn observability_pool(&self) -> &PgPool
pub fn observability_pool(&self) -> &PgPool
Pool for observability writes (metrics, slow query logs). Falls back to primary if no isolated pool is configured.
Sourcepub fn analytics_pool(&self) -> &PgPool
pub fn analytics_pool(&self) -> &PgPool
Pool for long-running analytics queries. Falls back to primary if no isolated pool is configured.
Sourcepub fn start_health_monitor(&self) -> Option<JoinHandle<()>>
pub fn start_health_monitor(&self) -> Option<JoinHandle<()>>
Start background health monitoring for replicas. Returns None if no replicas configured.
Sourcepub async fn health_check(&self) -> Result<()>
pub async fn health_check(&self) -> Result<()>
Check database connectivity.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more