90 lines
2.1 KiB
Rust
Raw Normal View History

/// A parsed `SELECT-FROM-WHERE-ORDER BY-LIMIT` 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>,
2026-04-10 09:56:18 +02:00
/// Source tables and their optional aliases.
pub from: Vec<TableRef>,
/// Optional filter predicate.
2026-04-09 12:38:43 +02:00
pub selection: Option<Expr>,
2026-04-10 10:10:46 +02:00
/// Optional output ordering.
pub order_by: Vec<OrderByItem>,
/// Optional row limit.
pub limit: Option<usize>,
2026-04-09 12:38:43 +02:00
}
2026-04-10 09:56:18 +02:00
/// 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>,
}
2026-04-10 10:10:46 +02:00
/// 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.
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),
/// An integer literal.
Integer(i64),
/// 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,
/// Inequality.
Ne,
/// Boolean conjunction.
And,
/// Boolean disjunction.
Or,
2026-04-09 12:38:43 +02:00
}
2026-04-10 10:10:46 +02:00
/// Sort direction for `ORDER BY`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SortDirection {
/// Ascending order.
Asc,
/// Descending order.
Desc,
}