51 lines
1.2 KiB
Rust
Raw Normal View History

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