spacetimedb_sql_parser/ast/
mod.rsuse std::fmt::{Display, Formatter};
use sqlparser::ast::Ident;
pub mod sql;
pub mod sub;
#[derive(Debug)]
pub enum SqlFrom<Ast> {
Expr(RelExpr<Ast>, Option<SqlIdent>),
Join(RelExpr<Ast>, SqlIdent, Vec<SqlJoin<Ast>>),
}
#[derive(Debug)]
pub enum RelExpr<Ast> {
Var(SqlIdent),
Ast(Box<Ast>),
}
#[derive(Debug)]
pub struct SqlJoin<Ast> {
pub expr: RelExpr<Ast>,
pub alias: SqlIdent,
pub on: Option<SqlExpr>,
}
#[derive(Debug)]
pub struct ProjectElem(pub ProjectExpr, pub Option<SqlIdent>);
#[derive(Debug)]
pub enum ProjectExpr {
Var(SqlIdent),
Field(SqlIdent, SqlIdent),
}
#[derive(Debug)]
pub enum Project {
Star(Option<SqlIdent>),
Exprs(Vec<ProjectElem>),
}
#[derive(Debug)]
pub enum SqlExpr {
Lit(SqlLiteral),
Var(SqlIdent),
Field(SqlIdent, SqlIdent),
Bin(Box<SqlExpr>, Box<SqlExpr>, BinOp),
}
#[derive(Debug, Clone)]
pub struct SqlIdent {
pub name: String,
pub case_sensitive: bool,
}
impl From<Ident> for SqlIdent {
fn from(value: Ident) -> Self {
match value {
Ident {
value: name,
quote_style: None,
} => SqlIdent {
name,
case_sensitive: false,
},
Ident {
value: name,
quote_style: Some(_),
} => SqlIdent {
name,
case_sensitive: true,
},
}
}
}
#[derive(Debug)]
pub enum SqlLiteral {
Bool(bool),
Hex(String),
Num(String),
Str(String),
}
#[derive(Debug, Clone, Copy)]
pub enum BinOp {
Eq,
Ne,
Lt,
Gt,
Lte,
Gte,
And,
Or,
}
impl Display for BinOp {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Eq => write!(f, "="),
Self::Ne => write!(f, "<>"),
Self::Lt => write!(f, "<"),
Self::Gt => write!(f, ">"),
Self::Lte => write!(f, "<="),
Self::Gte => write!(f, ">="),
Self::And => write!(f, "AND"),
Self::Or => write!(f, "OR"),
}
}
}