Skip to main content

vantage_table/traits/
table_like.rs

1use async_trait::async_trait;
2use vantage_core::Result;
3use vantage_dataset::prelude::{ReadableValueSet, WritableValueSet};
4use vantage_expressions::AnyExpression;
5
6use crate::{conditions::ConditionHandle, pagination::Pagination};
7
8/// Dyn-safe trait for table operations.
9#[async_trait]
10pub trait TableLike: ReadableValueSet + WritableValueSet + Send + Sync {
11    fn table_name(&self) -> &str;
12    fn table_alias(&self) -> &str;
13    fn column_names(&self) -> Vec<String>;
14
15    /// Add a condition to this table using a type-erased expression
16    /// The expression must be of type T::Expr for the underlying table's TableSource
17    fn add_condition(&mut self, condition: Box<dyn std::any::Any + Send + Sync>) -> Result<()>;
18
19    /// Add a temporary condition using AnyExpression that can be removed later
20    fn temp_add_condition(&mut self, condition: AnyExpression) -> Result<ConditionHandle>;
21
22    /// Remove a temporary condition by its handle
23    fn temp_remove_condition(&mut self, handle: ConditionHandle) -> Result<()>;
24
25    /// Create a search expression for this table
26    fn search_expression(&self, search_value: &str) -> Result<AnyExpression>;
27
28    /// Clone into a Box for object-safe cloning
29    fn clone_box(&self) -> Box<dyn TableLike<Value = Self::Value, Id = Self::Id>>;
30
31    /// Convert to Any for downcasting
32    fn into_any(self: Box<Self>) -> Box<dyn std::any::Any>;
33    fn as_any_ref(&self) -> &dyn std::any::Any;
34
35    /// Set pagination for this table
36    fn set_pagination(&mut self, pagination: Option<Pagination>);
37
38    /// Get pagination for this table
39    fn get_pagination(&self) -> Option<&Pagination>;
40
41    /// Get count of records in the table
42    async fn get_count(&self) -> Result<i64>;
43}