sad-spirit / pg-builder

Query builder for Postgres backed by SQL parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

More specialized Node subclasses

sad-spirit opened this issue · comments

There were quite a lot corners cut when implementing Parser, so it ended up generating fewer subclasses of Node than reasonable.

The most obvious example is OperatorExpression class that accepts any string as an operator and any Expressions as operands. Fixing this will require at least implementing

  • a QualifiedOperator node that will represent operator(namespace.###) construct
  • an IsExpression node representing foo IS [NOT] SOMETHING, obviously it will have only left argument
  • an IsDistinctExpression node for foo IS [NOT] DISTINCT FROM bar
  • a NotExpression node for 'NOT something`, with only right argument
  • an OverlapsExpression node allowing only RowExpressions as arguments
  • an AtTimeZoneExpression with only left argument

after that OperatorExpression may be changed to check that its operator is either a Token of applicable type or an instance of QualifiedOperator

Also move associativity and precedence constants from SqlBuilderWalker to ScalarExpression (and SetOpSelect), define getAssociativity() and getPrecedence() in ScalarExpression and implement in relevant nodes.

This will prevent errors when new nodes are added to support new syntax, see e.g. commit 1c9036b