use serde_json::Value;
use std::future::Future;
use crate::Expression;
use crate::Selectable;
use crate::traits::associated_expressions::AssociatedExpression;
use crate::traits::expressive::DeferredFn;
use vantage_core::Result;
pub trait DataSource: Send + Sync {}
pub trait ExprDataSource<T = Value>: DataSource {
fn execute(&self, expr: &crate::Expression<T>) -> impl Future<Output = Result<T>> + Send;
fn defer(&self, expr: crate::Expression<T>) -> DeferredFn<T>
where
T: Clone + Send + Sync + 'static;
fn associate<R>(&self, expr: crate::Expression<T>) -> AssociatedExpression<'_, Self, T, R>
where
Self: Sized,
{
AssociatedExpression::new(expr, self)
}
}
pub trait SelectableDataSource<T = Value, C = Expression<T>>: DataSource {
type Select: Selectable<T, C>;
fn select(&self) -> Self::Select;
fn execute_select(&self, select: &Self::Select) -> impl Future<Output = Result<Vec<T>>> + Send;
fn add_select_column(
&self,
select: &mut Self::Select,
expression: Expression<T>,
alias: Option<&str>,
) where
T: Clone,
{
if alias.is_some() {
panic!("add_select_column with alias not implemented for this backend");
}
select.add_expression(expression);
}
}