mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-09 03:04:20 +01:00
sqlite3-parser: separate boxed SelectInner struct
This commit is contained in:
@@ -305,7 +305,10 @@ impl OneSelect {
|
||||
/// Like `sqlite3_column_count` but more limited
|
||||
pub fn column_count(&self) -> ColumnCount {
|
||||
match self {
|
||||
Self::Select { columns, .. } => column_count(columns),
|
||||
Self::Select(select) => {
|
||||
let SelectInner { columns, .. } = &**select;
|
||||
column_count(columns)
|
||||
}
|
||||
Self::Values(values) => {
|
||||
assert!(!values.is_empty()); // TODO Validate
|
||||
ColumnCount::Fixed(values[0].len())
|
||||
|
||||
@@ -893,14 +893,15 @@ impl Display for CompoundOperator {
|
||||
impl ToTokens for OneSelect {
|
||||
fn to_tokens<S: TokenStream>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
match self {
|
||||
Self::Select {
|
||||
distinctness,
|
||||
columns,
|
||||
from,
|
||||
where_clause,
|
||||
group_by,
|
||||
window_clause,
|
||||
} => {
|
||||
Self::Select(select) => {
|
||||
let SelectInner {
|
||||
distinctness,
|
||||
columns,
|
||||
from,
|
||||
where_clause,
|
||||
group_by,
|
||||
window_clause,
|
||||
} = &**select;
|
||||
s.append(TK_SELECT, None)?;
|
||||
if let Some(ref distinctness) = distinctness {
|
||||
distinctness.to_tokens(s)?;
|
||||
|
||||
@@ -779,24 +779,28 @@ pub enum CompoundOperator {
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum OneSelect {
|
||||
/// `SELECT`
|
||||
Select {
|
||||
/// `DISTINCT`
|
||||
distinctness: Option<Distinctness>,
|
||||
/// columns
|
||||
columns: Vec<ResultColumn>,
|
||||
/// `FROM` clause
|
||||
from: Option<FromClause>,
|
||||
/// `WHERE` clause
|
||||
where_clause: Option<Expr>,
|
||||
/// `GROUP BY`
|
||||
group_by: Option<GroupBy>,
|
||||
/// `WINDOW` definition
|
||||
window_clause: Option<Vec<WindowDef>>,
|
||||
},
|
||||
Select(Box<SelectInner>),
|
||||
/// `VALUES`
|
||||
Values(Vec<Vec<Expr>>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
/// `SELECT` core
|
||||
pub struct SelectInner {
|
||||
/// `DISTINCT`
|
||||
pub distinctness: Option<Distinctness>,
|
||||
/// columns
|
||||
pub columns: Vec<ResultColumn>,
|
||||
/// `FROM` clause
|
||||
pub from: Option<FromClause>,
|
||||
/// `WHERE` clause
|
||||
pub where_clause: Option<Expr>,
|
||||
/// `GROUP BY`
|
||||
pub group_by: Option<GroupBy>,
|
||||
/// `WINDOW` definition
|
||||
pub window_clause: Option<Vec<WindowDef>>,
|
||||
}
|
||||
|
||||
/// `SELECT` ... `FROM` clause
|
||||
// https://sqlite.org/syntax/join-clause.html
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
||||
@@ -525,14 +525,14 @@ multiselect_op(A) ::= INTERSECT. {A = CompoundOperator::Intersect;}
|
||||
|
||||
oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
|
||||
groupby_opt(P). {
|
||||
A = OneSelect::Select{ distinctness: D, columns: W, from: X, where_clause: Y,
|
||||
group_by: P, window_clause: None };
|
||||
A = OneSelect::Select(Box::new(SelectInner{ distinctness: D, columns: W, from: X, where_clause: Y,
|
||||
group_by: P, window_clause: None }));
|
||||
}
|
||||
%ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
|
||||
groupby_opt(P) window_clause(R). {
|
||||
A = OneSelect::Select{ distinctness: D, columns: W, from: X, where_clause: Y,
|
||||
group_by: P, window_clause: Some(R) };
|
||||
A = OneSelect::Select(Box::new(SelectInner{ distinctness: D, columns: W, from: X, where_clause: Y,
|
||||
group_by: P, window_clause: Some(R) }));
|
||||
}
|
||||
%endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user