Function sqlparser::ast::visit_relations_mut

source ·
pub fn visit_relations_mut<V, E, F>(v: &mut V, f: F) -> ControlFlow<E>
where V: VisitMut, F: FnMut(&mut ObjectName) -> ControlFlow<E>,
Expand description

Invokes the provided closure with a mutable reference to all relations (e.g. table names) present in v.

When the closure mutates its argument, the new mutated relation will not be visited again.

§Example

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

// visit statements, renaming table foo to bar
visit_relations_mut(&mut statements, |table| {
  table.0[0].value = table.0[0].value.replace("foo", "bar");
  ControlFlow::<()>::Continue(())
});

assert_eq!(statements[0].to_string(), "SELECT a FROM bar");