pub struct Database { /* private fields */ }Expand description
Database client with connection pooling
Implementations§
Source§impl Database
impl Database
Sourcepub async fn new(config: DatabaseConfig) -> Result<Self>
pub async fn new(config: DatabaseConfig) -> Result<Self>
Create a new database client with connection pool
Sourcepub async fn from_url(url: &str) -> Result<Self>
pub async fn from_url(url: &str) -> Result<Self>
Create a new database client from a connection URL
Sourcepub async fn insert_event(&self, event: &AnalyticsEvent) -> Result<Uuid>
pub async fn insert_event(&self, event: &AnalyticsEvent) -> Result<Uuid>
Insert a single analytics event
Sourcepub async fn insert_events_batch(
&self,
events: &[AnalyticsEvent],
) -> Result<u64>
pub async fn insert_events_batch( &self, events: &[AnalyticsEvent], ) -> Result<u64>
Batch insert analytics events for high throughput
Sourcepub async fn query_events(
&self,
start: DateTime<Utc>,
end: DateTime<Utc>,
limit: Option<i64>,
) -> Result<Vec<AnalyticsEvent>>
pub async fn query_events( &self, start: DateTime<Utc>, end: DateTime<Utc>, limit: Option<i64>, ) -> Result<Vec<AnalyticsEvent>>
Query events by time range
Sourcepub async fn query_events_by_correlation(
&self,
correlation_id: Uuid,
) -> Result<Vec<AnalyticsEvent>>
pub async fn query_events_by_correlation( &self, correlation_id: Uuid, ) -> Result<Vec<AnalyticsEvent>>
Query events by correlation ID
Sourcepub async fn store_aggregated_metric(
&self,
metric_name: &str,
time_window: TimeWindow,
window_start: DateTime<Utc>,
tags: &Value,
measures: &StatisticalMeasures,
) -> Result<()>
pub async fn store_aggregated_metric( &self, metric_name: &str, time_window: TimeWindow, window_start: DateTime<Utc>, tags: &Value, measures: &StatisticalMeasures, ) -> Result<()>
Store aggregated metrics
Sourcepub async fn query_aggregated_metrics(
&self,
metric_name: &str,
time_window: TimeWindow,
start: DateTime<Utc>,
end: DateTime<Utc>,
) -> Result<Vec<AggregatedMetricRow>>
pub async fn query_aggregated_metrics( &self, metric_name: &str, time_window: TimeWindow, start: DateTime<Utc>, end: DateTime<Utc>, ) -> Result<Vec<AggregatedMetricRow>>
Query aggregated metrics
Sourcepub async fn store_anomaly(
&self,
anomaly_id: Uuid,
detected_at: DateTime<Utc>,
metric_name: &str,
anomaly_type: &str,
severity: &str,
value: f64,
expected_value: Option<f64>,
confidence_score: f64,
context: &Value,
) -> Result<Uuid>
pub async fn store_anomaly( &self, anomaly_id: Uuid, detected_at: DateTime<Utc>, metric_name: &str, anomaly_type: &str, severity: &str, value: f64, expected_value: Option<f64>, confidence_score: f64, context: &Value, ) -> Result<Uuid>
Store detected anomaly
Sourcepub async fn query_recent_anomalies(
&self,
since: DateTime<Utc>,
limit: Option<i64>,
) -> Result<Vec<AnomalyRow>>
pub async fn query_recent_anomalies( &self, since: DateTime<Utc>, limit: Option<i64>, ) -> Result<Vec<AnomalyRow>>
Query recent anomalies
Sourcepub async fn store_correlation(
&self,
correlation_id: Uuid,
correlation_type: &str,
source_event_id: Uuid,
target_event_id: Uuid,
strength: f64,
metadata: &Value,
) -> Result<Uuid>
pub async fn store_correlation( &self, correlation_id: Uuid, correlation_type: &str, source_event_id: Uuid, target_event_id: Uuid, strength: f64, metadata: &Value, ) -> Result<Uuid>
Store event correlation
Sourcepub async fn health_check(&self) -> Result<DatabaseHealth>
pub async fn health_check(&self) -> Result<DatabaseHealth>
Check database health
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 moreCreates a shared type from an unshared type.