Skip to main content

vantage_table/table/impls/
expr.rs

1//! Expression-related implementations for Table
2//!
3//! This module provides methods for creating AssociatedExpressions that can be
4//! both executed directly and composed into larger expressions.
5
6use std::ops::AddAssign;
7
8use vantage_expressions::{AssociatedExpression, traits::datasource::ExprDataSource};
9use vantage_types::Entity;
10
11use crate::{
12    column::core::ColumnType,
13    table::Table,
14    traits::{table_expr_source::TableExprSource, table_source::TableSource},
15};
16
17impl<T, E> Table<T, E>
18where
19    T: TableSource + ExprDataSource<T::Value> + TableExprSource,
20    E: Entity<T::Value>,
21{
22    /// Get an expression for counting rows in this table
23    /// Returns an AssociatedExpression that can be executed or composed
24    pub fn get_expr_count(&self) -> AssociatedExpression<'_, T, T::Value, usize>
25    where
26        T::Value: From<String>,
27    {
28        self.data_source().get_table_count_expr(self)
29    }
30
31    /// Get an expression for the sum of a column
32    /// Returns an AssociatedExpression that can be executed or composed
33    pub fn get_expr_sum<R: ColumnType + Default + AddAssign>(
34        &self,
35        column: &T::Column<R>,
36    ) -> AssociatedExpression<'_, T, T::Value, R> {
37        self.data_source().get_table_sum_expr(self, column)
38    }
39
40    /// Get an expression for the maximum value of a column
41    /// Returns an AssociatedExpression that can be executed or composed
42    pub fn get_expr_max<R: ColumnType + Default + AddAssign>(
43        &self,
44        column: &T::Column<R>,
45    ) -> AssociatedExpression<'_, T, T::Value, R> {
46        self.data_source().get_table_max_expr(self, column)
47    }
48
49    /// Get an expression for the minimum value of a column
50    /// Returns an AssociatedExpression that can be executed or composed
51    pub fn get_expr_min<R: ColumnType + Default + AddAssign>(
52        &self,
53        column: &T::Column<R>,
54    ) -> AssociatedExpression<'_, T, T::Value, R> {
55        self.data_source().get_table_min_expr(self, column)
56    }
57}