velesdb_core/observer.rs
1//! `DatabaseObserver` — extension hook for velesdb-premium.
2//!
3//! The core library has zero knowledge of Premium internals.
4//! Premium implements this trait and injects it via
5//! [`Database::open_with_observer`](crate::Database::open_with_observer).
6//!
7//! # Contract
8//!
9//! - All methods have default no-op implementations.
10//! - Implementations MUST be `Send + Sync`.
11//! - Implementations MUST NOT panic.
12//! - Overhead when `observer` is `None` is a single pointer check.
13
14use crate::collection::CollectionType;
15
16/// Lifecycle hooks for database events.
17///
18/// Implement this trait in `velesdb-premium` to attach RBAC, audit logging,
19/// multi-tenant routing, or replication logic without modifying the core.
20///
21/// # Example (Premium side)
22///
23/// ```rust,ignore
24/// use velesdb_core::{DatabaseObserver, CollectionType};
25///
26/// struct PremiumObserver { /* audit_log, rbac, tenant_router */ }
27///
28/// impl DatabaseObserver for PremiumObserver {
29/// fn on_collection_created(&self, name: &str, kind: &CollectionType) {
30/// // self.audit_log.record(...)
31/// }
32/// }
33/// ```
34pub trait DatabaseObserver: Send + Sync {
35 /// Called after a collection is successfully created.
36 fn on_collection_created(&self, _name: &str, _kind: &CollectionType) {}
37
38 /// Called after a collection is successfully deleted.
39 fn on_collection_deleted(&self, _name: &str) {}
40
41 /// Called after points are upserted into a collection.
42 fn on_upsert(&self, _collection: &str, _point_count: usize) {}
43
44 /// Called after a query is executed, with the duration in microseconds.
45 fn on_query(&self, _collection: &str, _duration_us: u64) {}
46}