vantage_expressions/traits/
datasource.rs1use serde_json::Value;
2use std::future::Future;
3
4use crate::Expression;
5use crate::Selectable;
6use crate::traits::associated_expressions::AssociatedExpression;
7use crate::traits::expressive::DeferredFn;
8use vantage_core::Result;
9
10pub trait DataSource: Send + Sync {}
15
16pub trait ExprDataSource<T = Value>: DataSource {
18 fn execute(&self, expr: &crate::Expression<T>) -> impl Future<Output = Result<T>> + Send;
19
20 fn defer(&self, expr: crate::Expression<T>) -> DeferredFn<T>
21 where
22 T: Clone + Send + Sync + 'static;
23
24 fn associate<R>(&self, expr: crate::Expression<T>) -> AssociatedExpression<'_, Self, T, R>
34 where
35 Self: Sized,
36 {
37 AssociatedExpression::new(expr, self)
38 }
39}
40
41pub trait SelectableDataSource<T = Value, C = Expression<T>>: DataSource {
43 type Select: Selectable<T, C>;
44
45 fn select(&self) -> Self::Select;
47
48 fn execute_select(&self, select: &Self::Select) -> impl Future<Output = Result<Vec<T>>> + Send;
50
51 fn add_select_column(
54 &self,
55 select: &mut Self::Select,
56 expression: Expression<T>,
57 alias: Option<&str>,
58 ) where
59 T: Clone,
60 {
61 if alias.is_some() {
62 panic!("add_select_column with alias not implemented for this backend");
63 }
64 select.add_expression(expression);
65 }
66}