Skip to content

Commit 7482906

Browse files
committed
add {pre,post}_visit_query
1 parent dc2ceed commit 7482906

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/ast/query.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::ast::*;
2626
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
2727
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
2828
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
29+
#[cfg_attr(feature = "visitor", visit(with = "visit_query"))]
2930
pub struct Query {
3031
/// WITH (common table expressions, or CTEs)
3132
pub with: Option<With>,

src/ast/visitor.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
//! Recursive visitors for ast Nodes. See [`Visitor`] for more details.
1414
15-
use crate::ast::{Expr, ObjectName, Statement, TableFactor};
15+
use crate::ast::{Expr, ObjectName, Query, Statement, TableFactor};
1616
use core::ops::ControlFlow;
1717

1818
/// A type that can be visited by a [`Visitor`]. See [`Visitor`] for
@@ -179,6 +179,16 @@ pub trait Visitor {
179179
/// Type returned when the recursion returns early.
180180
type Break;
181181

182+
/// Invoked for any queries that appear in the AST before visiting children
183+
fn pre_visit_query(&mut self, _query: &Query) -> ControlFlow<Self::Break> {
184+
ControlFlow::Continue(())
185+
}
186+
187+
/// Invoked for any queries that appear in the AST after visiting children
188+
fn post_visit_query(&mut self, _query: &Query) -> ControlFlow<Self::Break> {
189+
ControlFlow::Continue(())
190+
}
191+
182192
/// Invoked for any relations (e.g. tables) that appear in the AST before visiting children
183193
fn pre_visit_relation(&mut self, _relation: &ObjectName) -> ControlFlow<Self::Break> {
184194
ControlFlow::Continue(())
@@ -267,6 +277,16 @@ pub trait VisitorMut {
267277
/// Type returned when the recursion returns early.
268278
type Break;
269279

280+
/// Invoked for any queries that appear in the AST before visiting children
281+
fn pre_visit_query(&mut self, _query: &mut Query) -> ControlFlow<Self::Break> {
282+
ControlFlow::Continue(())
283+
}
284+
285+
/// Invoked for any queries that appear in the AST after visiting children
286+
fn post_visit_query(&mut self, _query: &mut Query) -> ControlFlow<Self::Break> {
287+
ControlFlow::Continue(())
288+
}
289+
270290
/// Invoked for any relations (e.g. tables) that appear in the AST before visiting children
271291
fn pre_visit_relation(&mut self, _relation: &mut ObjectName) -> ControlFlow<Self::Break> {
272292
ControlFlow::Continue(())

0 commit comments

Comments
 (0)