2026-04-09 12:50:06 +02:00
|
|
|
/// A parsed `SELECT-FROM-WHERE` statement in the current SQL subset.
|
2026-04-09 12:38:43 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub struct Select {
|
2026-04-09 12:50:06 +02:00
|
|
|
/// Output expressions requested by the query.
|
2026-04-09 12:38:43 +02:00
|
|
|
pub projection: Vec<SelectItem>,
|
2026-04-09 12:50:06 +02:00
|
|
|
/// Source table name.
|
2026-04-09 12:38:43 +02:00
|
|
|
pub from: String,
|
2026-04-09 12:50:06 +02:00
|
|
|
/// Optional filter predicate.
|
2026-04-09 12:38:43 +02:00
|
|
|
pub selection: Option<Expr>,
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 12:50:06 +02:00
|
|
|
/// One item in a `SELECT` projection list.
|
2026-04-09 12:38:43 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum SelectItem {
|
2026-04-09 12:50:06 +02:00
|
|
|
/// `*`
|
2026-04-09 12:38:43 +02:00
|
|
|
Wildcard,
|
2026-04-09 12:50:06 +02:00
|
|
|
/// A projected expression, optionally renamed with `AS`.
|
2026-04-09 12:38:43 +02:00
|
|
|
Expr { expr: Expr, alias: Option<String> },
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 12:50:06 +02:00
|
|
|
/// A SQL expression in the current subset.
|
2026-04-09 12:38:43 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum Expr {
|
2026-04-09 12:50:06 +02:00
|
|
|
/// A column reference.
|
2026-04-09 12:38:43 +02:00
|
|
|
Identifier(String),
|
2026-04-09 12:50:06 +02:00
|
|
|
/// A literal value.
|
2026-04-09 12:38:43 +02:00
|
|
|
Literal(Literal),
|
2026-04-09 12:50:06 +02:00
|
|
|
/// A binary expression.
|
2026-04-09 12:38:43 +02:00
|
|
|
Binary {
|
|
|
|
|
left: Box<Expr>,
|
|
|
|
|
op: BinaryOp,
|
|
|
|
|
right: Box<Expr>,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 12:50:06 +02:00
|
|
|
/// A SQL literal in the current subset.
|
2026-04-09 12:38:43 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
|
pub enum Literal {
|
2026-04-09 12:50:06 +02:00
|
|
|
/// A string literal.
|
2026-04-09 12:38:43 +02:00
|
|
|
String(String),
|
2026-04-09 12:50:06 +02:00
|
|
|
/// The `NULL` literal.
|
2026-04-09 12:38:43 +02:00
|
|
|
Null,
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 12:50:06 +02:00
|
|
|
/// A binary operator in the current subset.
|
2026-04-09 12:38:43 +02:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
pub enum BinaryOp {
|
2026-04-09 12:50:06 +02:00
|
|
|
/// Equality.
|
2026-04-09 12:38:43 +02:00
|
|
|
Eq,
|
|
|
|
|
}
|