use crate::{ConflictResolution, Expr, IndexedColumn, SchemaObject};
#[derive(Clone, Debug, PartialEq)]
pub enum Dml {
Select(Select),
Insert(Insert),
Update(Update),
Delete(Delete),
}
#[derive(Clone, Debug, PartialEq)]
pub struct Select {
pub core: SelectCore,
pub compound: Vec<(CompoundOperator, SelectCore)>,
pub order_by: Vec<OrderingTerm>,
pub limit: Option<Expr>,
pub offset: Option<Expr>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Insert {
pub header: InsertHeader,
pub schema_table: SchemaObject,
pub alias: Option<String>,
pub cols: Vec<String>,
pub values: InsertValues,
pub return_clause: Vec<ReturnSubClause>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Update {
pub conflict: ConflictResolution,
pub qualified_table: QualifiedTable,
pub set_clause: Vec<SetSubClause>,
pub from_clause: Option<FromClause>,
pub where_clause: Option<Expr>,
pub return_clause: Vec<ReturnSubClause>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct Delete {
pub qualified_table: QualifiedTable,
pub where_clause: Option<Expr>,
pub return_clause: Vec<ReturnSubClause>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum SelectCore {
Query(Query),
Values(Vec<Vec<Expr>>),
}
#[derive(Clone, Debug, PartialEq)]
pub struct Query {
pub is_distinct: bool,
pub cols: Vec<ResultColumn>,
pub from_clause: Option<FromClause>,
pub where_clause: Option<Expr>,
pub group_by: Vec<Expr>,
pub having: Option<Expr>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum ResultColumn {
Expr(Expr, Option<String>),
Star,
}
#[derive(Clone, Debug, PartialEq)]
pub enum InsertValues {
Values {
values: Vec<Vec<Expr>>,
upsert: Option<UpsertSubClause>,
},
Select {
select: Box<Select>,
upsert: Option<UpsertSubClause>,
},
Default,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SetSubClause {
pub cols: Vec<String>,
pub value: Expr,
}
#[derive(Clone, Debug, PartialEq)]
pub struct JoinClause {
pub table_or_subquery: QualifiedTable,
pub joins: Vec<JoinSubClause>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct JoinSubClause {
pub operator: JoinOperator,
pub table_or_subquery: QualifiedTable,
pub constraint: Option<JoinConstraint>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum JoinOperator {
Comma,
Cross,
Inner(bool),
Outer(bool, OuterJoinType),
}
#[derive(Clone, Debug, PartialEq)]
pub enum OuterJoinType {
Left,
Right,
Full,
}
#[derive(Clone, Debug, PartialEq)]
pub enum JoinConstraint {
Expr(Expr), Using(Vec<String>), }
#[derive(Clone, Debug, PartialEq)]
pub struct QualifiedTable {
pub schema_table: SchemaObject,
pub alias: Option<String>,
pub indexed: Option<Indexed>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Indexed {
By(String),
NotIndexed,
}
#[derive(Clone, Debug, PartialEq)]
pub enum FromClause {
TableOrQuerys(Vec<QualifiedTable>),
Join(JoinClause),
}
#[derive(Clone, Debug, PartialEq)]
pub struct OrderingTerm {
pub expr: Expr,
pub asc: bool,
pub nulls_first: bool, }
#[derive(Clone, Debug, PartialEq)]
pub enum ReturnSubClause {
Star,
Expr(Expr, Option<String>),
}
#[derive(Clone, Debug, PartialEq)]
pub enum InsertHeader {
Insert(ConflictResolution),
Replace,
}
#[derive(Clone, Debug, PartialEq)]
pub struct UpsertSubClause {
pub indexed_cols: Vec<IndexedColumn>,
pub where_clause: Option<Expr>,
pub upsert_type: UpsertType,
}
#[derive(Clone, Debug, PartialEq)]
pub enum UpsertType {
Nothing,
Update {
set_clause: Vec<SetSubClause>,
where_clause: Option<Expr>,
},
}
#[derive(Clone, Debug, PartialEq)]
pub enum CompoundOperator {
Union(bool), Intersect,
Except,
}