When crafting a query, a Query\Expression
instance can be used in the 'selectPrimary'
option. The expression wraps a string formatted according to a domain-specific language (DSL) for queries.
The primary PostgreSqlQueryBuilder
does not have any special knowledge what an Expression
is and how to parse it. Instead, the builder relies on visitors to extend existing functionality with new cases.
The visitor ExpressionQueryBuilderVisitor
is registered in the builder and is responsible for parsing the expression and adjusting the options of the query. When an Expression
instance is encountered in this visitor, the expression is parsed into an abstract syntax tree (AST). The original query is modified so that all columns which are mentioned in the expression are included to be SELECT'ed. E.g., the expression SUM("table"."column1" + "table"."column2")
will instruct the query builder to generate SQL code for "table"."column1"
and `"table"."column2"