VisitorMut in sqlparser::ast - Rust

pub trait VisitorMut {
    type Break;

    // Provided methods
    fn pre_visit_query(
        &mut self,
        _query: &mut Query,
    ) -> ControlFlow<Self::Break> { ... }
    fn post_visit_query(
        &mut self,
        _query: &mut Query,
    ) -> ControlFlow<Self::Break> { ... }
    fn pre_visit_relation(
        &mut self,
        _relation: &mut ObjectName,
    ) -> ControlFlow<Self::Break> { ... }
    fn post_visit_relation(
        &mut self,
        _relation: &mut ObjectName,
    ) -> ControlFlow<Self::Break> { ... }
    fn pre_visit_table_factor(
        &mut self,
        _table_factor: &mut TableFactor,
    ) -> ControlFlow<Self::Break> { ... }
    fn post_visit_table_factor(
        &mut self,
        _table_factor: &mut TableFactor,
    ) -> ControlFlow<Self::Break> { ... }
    fn pre_visit_expr(&mut self, _expr: &mut Expr) -> ControlFlow<Self::Break> { ... }
    fn post_visit_expr(&mut self, _expr: &mut Expr) -> ControlFlow<Self::Break> { ... }
    fn pre_visit_statement(
        &mut self,
        _statement: &mut Statement,
    ) -> ControlFlow<Self::Break> { ... }
    fn post_visit_statement(
        &mut self,
        _statement: &mut Statement,
    ) -> ControlFlow<Self::Break> { ... }
    fn pre_visit_value(
        &mut self,
        _value: &mut Value,
    ) -> ControlFlow<Self::Break> { ... }
    fn post_visit_value(
        &mut self,
        _value: &mut Value,
    ) -> ControlFlow<Self::Break> { ... }
}
Expand description

A visitor that can be used to mutate an AST tree.

pre_visit_ methods are invoked before visiting all children of the node and post_visit_ methods are invoked after visiting all children of the node.

§See also

These methods provide a more concise way of visiting nodes of a certain type:

§Example


// A visitor that replaces "to_replace" with "replaced" in all expressions
struct Replacer;

// Visit each expression after its children have been visited
impl VisitorMut for Replacer {
  type Break = ();

  fn post_visit_expr(&mut self, expr: &mut Expr) -> ControlFlow<Self::Break> {
    if let Expr::Identifier(Ident{ value, ..}) = expr {
        *value = value.replace("to_replace", "replaced")
    }
    ControlFlow::Continue(())
  }
}

let sql = "SELECT to_replace FROM foo where to_replace IN (SELECT to_replace FROM bar)";
let mut statements = Parser::parse_sql(&GenericDialect{}, sql).unwrap();

// Drive the visitor through the AST
statements.visit(&mut Replacer);

assert_eq!(statements[0].to_string(), "SELECT replaced FROM foo WHERE replaced IN (SELECT replaced FROM bar)");
Source

Type returned when the recursion returns early.

Important note: The Break type should be kept as small as possible to prevent stack overflow during recursion. If you need to return an error, consider boxing it with Box to minimize stack usage.

Source

Invoked for any queries that appear in the AST before visiting children

Source

Invoked for any queries that appear in the AST after visiting children

Source

Invoked for any relations (e.g. tables) that appear in the AST before visiting children

Source

Invoked for any relations (e.g. tables) that appear in the AST after visiting children

Source

Invoked for any table factors that appear in the AST before visiting children

Source

Invoked for any table factors that appear in the AST after visiting children

Source

Invoked for any expressions that appear in the AST before visiting children

Source

Invoked for any expressions that appear in the AST

Source

Invoked for any statements that appear in the AST before visiting children

Source

Invoked for any statements that appear in the AST after visiting children

Source

Invoked for any value that appear in the AST before visiting children

Source

Invoked for any statements that appear in the AST after visiting children