Skip to content

Commit 6c58e2d

Browse files
authored
Merge pull request #3 from groobyming/refactor/#122360719
refactor: sqlparser-rs 扩展 plain select --story=122360719
2 parents d2ee5e3 + cb4fe49 commit 6c58e2d

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

src/ast/query.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ pub enum SelectFlavor {
294294
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
295295
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
296296
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
297+
#[cfg_attr(feature = "visitor", visit(with = "visit_select"))]
297298
pub struct Select {
298299
/// Token for the `SELECT` keyword
299300
pub select_token: AttachedToken,
@@ -304,6 +305,7 @@ pub struct Select {
304305
/// Whether the top was located before `ALL`/`DISTINCT`
305306
pub top_before_distinct: bool,
306307
/// projection expressions
308+
#[cfg_attr(feature = "visitor", visit(with = "visit_projection"))]
307309
pub projection: Vec<SelectItem>,
308310
/// INTO
309311
pub into: Option<SelectInto>,
@@ -541,6 +543,7 @@ impl fmt::Display for NamedWindowDefinition {
541543
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
542544
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
543545
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
546+
#[cfg_attr(feature = "visitor", visit(with = "visit_with"))]
544547
pub struct With {
545548
/// Token for the "WITH" keyword
546549
pub with_token: AttachedToken,

src/ast/visitor.rs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
//! Recursive visitors for ast Nodes. See [`Visitor`] for more details.
1919
2020
use crate::ast::{
21-
Expr, Function, GroupByExpr, ObjectName, OrderBy, Query, SelectItem, Statement, TableFactor,
22-
Value,
21+
Expr, Function, GroupByExpr, ObjectName, OrderBy, Query, Select, SelectItem, Statement,
22+
TableFactor, Value, With,
2323
};
2424
use core::ops::ControlFlow;
2525
use sqlparser::ast::Ident;
@@ -307,6 +307,36 @@ pub trait Visitor {
307307
fn post_visit_order_by(&mut self, _order_by: &OrderBy) -> ControlFlow<Self::Break> {
308308
ControlFlow::Continue(())
309309
}
310+
311+
/// Invoked for any Select that appear in the AST before visiting children
312+
fn pre_visit_select(&mut self, _select: &Select) -> ControlFlow<Self::Break> {
313+
ControlFlow::Continue(())
314+
}
315+
316+
/// Invoked for any Select that appear in the AST after visiting children
317+
fn post_visit_select(&mut self, _select: &Select) -> ControlFlow<Self::Break> {
318+
ControlFlow::Continue(())
319+
}
320+
321+
/// Invoked for any With that appear in the AST before visiting children
322+
fn pre_visit_with(&mut self, _select: &With) -> ControlFlow<Self::Break> {
323+
ControlFlow::Continue(())
324+
}
325+
326+
/// Invoked for any With that appear in the AST after visiting children
327+
fn post_visit_with(&mut self, _select: &With) -> ControlFlow<Self::Break> {
328+
ControlFlow::Continue(())
329+
}
330+
331+
/// Invoked for any Projection that appear in the AST before visiting children
332+
fn pre_visit_projection(&mut self, _select: &Vec<SelectItem>) -> ControlFlow<Self::Break> {
333+
ControlFlow::Continue(())
334+
}
335+
336+
/// Invoked for any Projection that appear in the AST after visiting children
337+
fn post_visit_projection(&mut self, _select: &Vec<SelectItem>) -> ControlFlow<Self::Break> {
338+
ControlFlow::Continue(())
339+
}
310340
}
311341

312342
/// A visitor that can be used to mutate an AST tree.
@@ -487,6 +517,36 @@ pub trait VisitorMut {
487517
fn post_visit_order_by(&mut self, _order_by: &mut OrderBy) -> ControlFlow<Self::Break> {
488518
ControlFlow::Continue(())
489519
}
520+
521+
/// Invoked for any Select Expr that appear in the AST before visiting children
522+
fn pre_visit_select(&mut self, _select: &mut Select) -> ControlFlow<Self::Break> {
523+
ControlFlow::Continue(())
524+
}
525+
526+
/// Invoked for any Select Expr that appear in the AST after visiting children
527+
fn post_visit_select(&mut self, _select: &mut Select) -> ControlFlow<Self::Break> {
528+
ControlFlow::Continue(())
529+
}
530+
531+
/// Invoked for any With Expr that appear in the AST before visiting children
532+
fn pre_visit_with(&mut self, _select: &mut With) -> ControlFlow<Self::Break> {
533+
ControlFlow::Continue(())
534+
}
535+
536+
/// Invoked for any With Expr that appear in the AST after visiting children
537+
fn post_visit_with(&mut self, _select: &mut With) -> ControlFlow<Self::Break> {
538+
ControlFlow::Continue(())
539+
}
540+
541+
/// Invoked for any Projection that appear in the AST before visiting children
542+
fn pre_visit_projection(&mut self, _select: &mut Vec<SelectItem>) -> ControlFlow<Self::Break> {
543+
ControlFlow::Continue(())
544+
}
545+
546+
/// Invoked for any Projection that appear in the AST after visiting children
547+
fn post_visit_projection(&mut self, _select: &mut Vec<SelectItem>) -> ControlFlow<Self::Break> {
548+
ControlFlow::Continue(())
549+
}
490550
}
491551

492552
struct RelationVisitor<F>(F);

0 commit comments

Comments
 (0)