findWrittenTables function

Set<TableWrite> findWrittenTables(
  1. AstNode root
)

Finds all writes to a table that occur anywhere inside the root node or a descendant.

The root node must have all its references resolved. This means that using a node obtained via SqlEngine.parse directly won't report meaningful results. Instead, use SqlEngine.analyze or SqlEngine.analyzeParsed.

If you want to find all referenced tables, use findReferencedTables. If you want to find writes (including their UpdateKind) and referenced tables, constrct a UpdatedTablesVisitor manually. Then, let it visit the root node. You can now use UpdatedTablesVisitor.writtenTables and ReferencedTablesVisitor.foundTables. This will only walk the ast once, whereas calling this and findReferencedTables will require two walks.

Implementation

Set<TableWrite> findWrittenTables(AstNode root) {
  return (UpdatedTablesVisitor()..visit(root, null)).writtenTables;
}