90 lines
2.1 KiB
Rust
90 lines
2.1 KiB
Rust
/// A parsed `SELECT-FROM-WHERE-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<SelectItem>,
|
|
/// Source tables and their optional aliases.
|
|
pub from: Vec<TableRef>,
|
|
/// Optional filter predicate.
|
|
pub selection: Option<Expr>,
|
|
/// Optional output ordering.
|
|
pub order_by: Vec<OrderByItem>,
|
|
/// Optional row limit.
|
|
pub limit: Option<usize>,
|
|
}
|
|
|
|
/// 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<String>,
|
|
}
|
|
|
|
/// 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<String> },
|
|
}
|
|
|
|
/// 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<Expr>,
|
|
op: BinaryOp,
|
|
right: Box<Expr>,
|
|
},
|
|
}
|
|
|
|
/// 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,
|
|
}
|