pganalyze / pg_query.rs

Rust library to parse, deparse and normalize SQL queries using the PostgreSQL query parser
MIT License
126 stars 12 forks source link

What are the goals of the `nodes()` functions? #31

Open absporl opened 1 year ago

absporl commented 1 year ago

Both NodesEnum::nodes() and protobuf::ParseResult::nodes() don't have documentation, although the latter hints

// Note: this doesn't iterate over every possible node type, since we only care about a subset of nodes.

Is the goal just to provide a helper function to extract ParseResult::{warnings, tables, aliases, cte_names, functions}?

I'm trying to do some more detailed parsing of a statement tree, and would like a "visitor" pattern. I need more information than scan() provides. Is it useful to extend the nodes function?

seanlinsley commented 1 year ago

Yes, nodes() was a bare minimum implementation to get the test suite passing (copied from the pg_query Ruby gem).

There isn't a foolproof way to know if we've covered all nested node types, but feel free to open a PR replacing the _ => () in the match as needed for your use case. Ideally with tests 😄