/// A parsed `SELECT-FROM-WHERE-GROUP BY-ORDER BY-LIMIT` statement in the /// current SQL subset. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Select { /// Output expressions requested by the query. pub projection: Vec, /// Source tables and their optional aliases. pub from: Vec, /// Optional filter predicate. pub selection: Option, /// Grouping columns. Empty means no `GROUP BY` clause. pub group_by: Vec, /// Optional output ordering. pub order_by: Vec, /// Optional row limit. pub limit: Option, } /// One source entry in a `FROM` list. #[derive(Debug, Clone, PartialEq, Eq)] pub struct TableRef { /// The predicate-backed table name. pub name: String, /// Optional table alias used for qualification. pub alias: Option, } /// One item in an `ORDER BY` clause. #[derive(Debug, Clone, PartialEq, Eq)] pub struct OrderByItem { /// Output column name to sort by. pub expr: Expr, /// Sort direction. pub direction: SortDirection, } /// One item in a `SELECT` projection list. #[derive(Debug, Clone, PartialEq, Eq)] pub enum SelectItem { /// `*` Wildcard, /// A projected expression, optionally renamed with `AS`. Expr { expr: Expr, alias: Option }, } /// A SQL expression in the current subset. #[derive(Debug, Clone, PartialEq, Eq)] pub enum Expr { /// A column reference. Identifier(String), /// A literal value. Literal(Literal), /// A binary expression. Binary { left: Box, op: BinaryOp, right: Box, }, /// An aggregate function applied to an argument. Aggregate { func: AggregateFunc, arg: AggregateArg, }, } /// An aggregate function in the current SQL subset. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum AggregateFunc { /// Row count (with `*`) or count of non-null values (with a column). Count, /// Sum of integer values. Sum, /// Minimum value. Min, /// Maximum value. Max, /// Arithmetic mean of integer values. Avg, } /// The argument to an aggregate function: either `*` (only valid for /// `COUNT`) or an expression. #[derive(Debug, Clone, PartialEq, Eq)] pub enum AggregateArg { /// `COUNT(*)` style argument. Star, /// An expression argument such as `SUM(col)`. Expr(Box), } /// A SQL literal in the current subset. #[derive(Debug, Clone, PartialEq, Eq)] pub enum Literal { /// A string literal. String(String), /// An integer literal. Integer(i64), /// The `NULL` literal. Null, } /// A binary operator in the current subset. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum BinaryOp { /// Equality. Eq, /// Inequality. Ne, /// Boolean conjunction. And, /// Boolean disjunction. Or, } /// Sort direction for `ORDER BY`. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum SortDirection { /// Ascending order. Asc, /// Descending order. Desc, }