Function sqlparser::ast::visit_relations
source · pub fn visit_relations<V, E, F>(v: &V, f: F) -> ControlFlow<E>where
V: Visit,
F: FnMut(&ObjectName) -> ControlFlow<E>,
Expand description
Invokes the provided closure on all relations (e.g. table names) present in v
Example
let sql = "SELECT a FROM foo where x IN (SELECT y FROM bar)";
let statements = Parser::parse_sql(&GenericDialect{}, sql)
.unwrap();
// visit statements, capturing relations (table names)
let mut visited = vec![];
visit_relations(&statements, |relation| {
visited.push(format!("RELATION: {}", relation));
ControlFlow::<()>::Continue(())
});
let expected : Vec<_> = [
"RELATION: foo",
"RELATION: bar",
]
.into_iter().map(|s| s.to_string()).collect();
assert_eq!(visited, expected);