pub struct MemEventsBackend { /* private fields */ }Expand description
Non-durable in-memory structured-event storage keyed by logical table name.
Rows are available immediately after append, which makes this backend useful for tests and local development.
§Examples
Facade wiring through Spectra::builder() (requires the spectra crate):
ⓘ
use std::sync::Arc;
use spectra::{MemEventsBackend, MemMetricsBackend, Spectra};
let spectra = Spectra::builder()
.metrics_backend(Arc::new(MemMetricsBackend::new()))
.events_backend(Arc::new(MemEventsBackend::new()))
.embedded()
.build()?;Direct backend usage:
use chrono::Utc;
use serde_json::json;
use spectra_backend_mem::MemEventsBackend;
use spectra_core::{EventStorageBackend, EventsQueryFilter};
let backend = MemEventsBackend::new();
backend.append_row(
"request_log",
&json!({"message": "handled"}),
Utc::now(),
None,
).await?;
let rows = backend.query_rows(EventsQueryFilter {
table: "request_log".into(),
..Default::default()
}).await?;
assert_eq!(rows.len(), 1);Implementations§
Source§impl MemEventsBackend
impl MemEventsBackend
Sourcepub fn new() -> MemEventsBackend
pub fn new() -> MemEventsBackend
Create an empty in-memory events backend.
Rows are keyed by logical table name and discarded when the process exits. Inject the
result into Spectra::builder().events_backend(...) for a full runtime.
§Examples
use spectra_backend_mem::MemEventsBackend;
use spectra_core::{EventStorageBackend, StorageEngineType};
let backend = MemEventsBackend::new();
assert_eq!(backend.engine_type(), StorageEngineType::Mem);Trait Implementations§
Source§impl Default for MemEventsBackend
impl Default for MemEventsBackend
Source§fn default() -> MemEventsBackend
fn default() -> MemEventsBackend
Returns the “default value” for a type. Read more
Source§impl EventStorageBackend for MemEventsBackend
impl EventStorageBackend for MemEventsBackend
Source§fn engine_type(&self) -> StorageEngineType
fn engine_type(&self) -> StorageEngineType
Returns the engine type for this backend.
Source§fn append_row<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
table: &'life1 str,
fields: &'life2 Value,
ts: DateTime<Utc>,
_correlation_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
MemEventsBackend: 'async_trait,
fn append_row<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
table: &'life1 str,
fields: &'life2 Value,
ts: DateTime<Utc>,
_correlation_id: Option<&'life3 str>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
MemEventsBackend: 'async_trait,
Appends one event row.
Source§fn query_rows<'life0, 'async_trait>(
&'life0 self,
filter: EventsQueryFilter,
) -> Pin<Box<dyn Future<Output = Result<Vec<EventRow>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemEventsBackend: 'async_trait,
fn query_rows<'life0, 'async_trait>(
&'life0 self,
filter: EventsQueryFilter,
) -> Pin<Box<dyn Future<Output = Result<Vec<EventRow>, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemEventsBackend: 'async_trait,
Queries event rows matching the filter.
Source§fn query_aggregate<'life0, 'async_trait>(
&'life0 self,
filter: EventsAggregateFilter,
) -> Pin<Box<dyn Future<Output = Result<EventAggregateResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemEventsBackend: 'async_trait,
fn query_aggregate<'life0, 'async_trait>(
&'life0 self,
filter: EventsAggregateFilter,
) -> Pin<Box<dyn Future<Output = Result<EventAggregateResult, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
MemEventsBackend: 'async_trait,
Queries aggregated chart data.
Source§fn append_rows_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
rows: &'life1 [EventWriteRow],
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn append_rows_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
rows: &'life1 [EventWriteRow],
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Batch append event rows (default: per-row dispatch).
Auto Trait Implementations§
impl !Freeze for MemEventsBackend
impl RefUnwindSafe for MemEventsBackend
impl Send for MemEventsBackend
impl Sync for MemEventsBackend
impl Unpin for MemEventsBackend
impl UnsafeUnpin for MemEventsBackend
impl UnwindSafe for MemEventsBackend
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