#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Statement {
Select(Box<Select>),
Insert(Insert),
Update(Update),
Delete(Delete),
Begin,
Commit,
Rollback,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Select {
pub distinct: bool,
pub projection: Projection,
pub from: TableRef,
pub joins: Vec<JoinClause>,
pub filter: Option<Condition>,
pub group_by: Vec<ColumnRef>,
pub having: Option<Condition>,
pub order_by: Vec<OrderItem>,
pub limit: Option<RowCount>,
pub offset: Option<RowCount>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Projection {
All,
Items(Vec<SelectItem>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SelectItem {
pub operand: Operand,
pub alias: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Operand {
Column(ColumnRef),
Aggregate(Aggregate),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColumnRef {
pub table: Option<String>,
pub column: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Aggregate {
pub function: AggregateKind,
pub column: Option<ColumnRef>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AggregateKind {
Count,
Sum,
Avg,
Min,
Max,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TableRef {
pub name: String,
pub alias: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct JoinClause {
pub kind: JoinKind,
pub table: TableRef,
pub left: ColumnRef,
pub right: ColumnRef,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum JoinKind {
Inner,
Left,
Right,
Full,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Condition {
And(Box<Condition>, Box<Condition>),
Or(Box<Condition>, Box<Condition>),
Not(Box<Condition>),
Compare {
operand: Operand,
op: CompareOp,
value: ValueExpr,
},
In {
operand: Operand,
values: Vec<ValueExpr>,
negated: bool,
},
Like {
operand: Operand,
pattern: ValueExpr,
negated: bool,
},
IsNull { operand: Operand, negated: bool },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompareOp {
Eq,
NotEq,
Lt,
LtEq,
Gt,
GtEq,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ValueExpr {
Literal(Literal),
Parameter(usize),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Literal {
Integer(i128),
Float(String),
String(String),
Boolean(bool),
Null,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OrderItem {
pub operand: Operand,
pub descending: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RowCount {
Value(u64),
Parameter(usize),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Insert {
pub table: String,
pub columns: Vec<String>,
pub values: Vec<ValueExpr>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Update {
pub table: String,
pub assignments: Vec<Assignment>,
pub filter: Condition,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Assignment {
pub column: String,
pub value: ValueExpr,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Delete {
pub table: String,
pub filter: Condition,
pub cascade: bool,
}