Skip to main content

DatabaseObserver

Trait DatabaseObserver 

Source
pub trait DatabaseObserver: Send + Sync {
    // Provided methods
    fn on_collection_created(&self, _name: &str, _kind: &CollectionType) { ... }
    fn on_collection_deleted(&self, _name: &str) { ... }
    fn on_upsert(&self, _collection: &str, _point_count: usize) { ... }
    fn on_query(&self, _collection: &str, _duration_us: u64) { ... }
    fn on_ddl_request(
        &self,
        operation: &str,
        collection_name: &str,
    ) -> Result<()> { ... }
    fn on_dml_mutation_request(
        &self,
        operation: &str,
        collection_name: &str,
    ) -> Result<()> { ... }
}
Expand description

Lifecycle hooks for database events.

Implement this trait in velesdb-premium to attach RBAC, audit logging, multi-tenant routing, or replication logic without modifying the core.

§Example (Premium side)

use velesdb_core::{DatabaseObserver, CollectionType};

struct PremiumObserver { /* audit_log, rbac, tenant_router */ }

impl DatabaseObserver for PremiumObserver {
    fn on_collection_created(&self, name: &str, kind: &CollectionType) {
        // self.audit_log.record(...)
    }
}

Provided Methods§

Source

fn on_collection_created(&self, _name: &str, _kind: &CollectionType)

Called after a collection is successfully created.

Source

fn on_collection_deleted(&self, _name: &str)

Called after a collection is successfully deleted.

Source

fn on_upsert(&self, _collection: &str, _point_count: usize)

Called after points are upserted into a collection.

Source

fn on_query(&self, _collection: &str, _duration_us: u64)

Called after a query is executed, with the duration in microseconds.

Source

fn on_ddl_request(&self, operation: &str, collection_name: &str) -> Result<()>

Called before a DDL statement is executed.

Premium extensions can implement this to enforce RBAC policies (e.g., only admin users can CREATE/DROP collections).

Returns Ok(()) to allow the DDL operation, or Err(Error) to reject it. Default implementation allows all DDL operations.

§Errors

Implementations should return an error to reject the DDL operation.

Source

fn on_dml_mutation_request( &self, operation: &str, collection_name: &str, ) -> Result<()>

Called before a mutating DML statement is executed.

Premium extensions can implement this to enforce RBAC policies (e.g., restrict INSERT EDGE, DELETE, or DELETE EDGE to authorized users).

Returns Ok(()) to allow the DML mutation, or Err(Error) to reject it. Default implementation allows all DML mutations.

§Errors

Implementations should return an error to reject the DML mutation.

Implementors§