Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit events while parsing #496

Open
labs20 opened this issue Nov 9, 2020 · 1 comment
Open

Emit events while parsing #496

labs20 opened this issue Nov 9, 2020 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@labs20
Copy link

labs20 commented Nov 9, 2020

Hi.

It would be very helpful if events were emitted while the parser is working, like "onColumn(col, sqlObj)", "onSubSelect(subSql, parentNode)", etc...

One could then implement validation and transform routines on the fly, while the targets are founding by the parser, instead of having to traverse the parser result afterwards.

Thanks!

@oguimbal
Copy link
Contributor

oguimbal commented Nov 9, 2020

IMO this is equivalent to an AST visitor, which is more flexible and simpler to implement (if you dont know it already, check out "visitor pattern" on google).

Example base class implementation here, and an example on how to use it here (not specific to the AST generated by node-sql-parser, though). Make it able transform things on the fly is quite easy. Exemple of what visitMember would look like:

 visitMember(val: ExprMember) {
        return { type: 'member', member: val.member, operand: this.visit(val.operand) }
}

Transofrming a ref would be quite easy doing so:

const transformedAst = new (class extends AstVisitor {
          visitRef(val: ExprRef) {
                 if (some condition)  return whatever;
                 return val;
         }).visit(myAst);

@taozhi8833998 taozhi8833998 added the enhancement New feature or request label May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants