vantage_table/traits/
table_like.rs1use async_trait::async_trait;
2use indexmap::IndexMap;
3use vantage_core::Result;
4use vantage_dataset::prelude::{ReadableValueSet, WritableValueSet};
5use vantage_expressions::AnyExpression;
6
7use crate::{conditions::ConditionHandle, pagination::Pagination};
8
9#[async_trait]
11pub trait TableLike: ReadableValueSet + WritableValueSet + Send + Sync {
12 fn table_name(&self) -> &str;
13 fn table_alias(&self) -> &str;
14 fn column_names(&self) -> Vec<String>;
15
16 fn set_table_name(&mut self, _name: String) {}
21
22 fn id_field_name(&self) -> Option<String> {
24 None
25 }
26
27 fn title_field_names(&self) -> Vec<String> {
29 Vec::new()
30 }
31
32 fn column_types(&self) -> IndexMap<String, &'static str> {
37 IndexMap::new()
38 }
39
40 fn get_ref_names(&self) -> Vec<String> {
42 Vec::new()
43 }
44
45 fn add_condition(&mut self, condition: Box<dyn std::any::Any + Send + Sync>) -> Result<()>;
48
49 fn add_condition_eq(&mut self, field: &str, value: &str) -> Result<()> {
56 let _ = (field, value);
57 Err(vantage_core::error!(
58 "add_condition_eq not supported on this TableLike"
59 ))
60 }
61
62 fn temp_add_condition(&mut self, condition: AnyExpression) -> Result<ConditionHandle>;
64
65 fn temp_remove_condition(&mut self, handle: ConditionHandle) -> Result<()>;
67
68 fn search_expression(&self, search_value: &str) -> Result<AnyExpression>;
70
71 fn clone_box(&self) -> Box<dyn TableLike<Value = Self::Value, Id = Self::Id>>;
73
74 fn into_any(self: Box<Self>) -> Box<dyn std::any::Any>;
76 fn as_any_ref(&self) -> &dyn std::any::Any;
77
78 fn set_pagination(&mut self, pagination: Option<Pagination>);
80
81 fn get_pagination(&self) -> Option<&Pagination>;
83
84 async fn get_count(&self) -> Result<i64>;
86}