api-docs / org.ktorm.expression / SqlExpressionVisitor
SqlExpressionVisitor
interface SqlExpressionVisitor
(source code)Base interface designed to visit or modify SQL expression trees using visitor pattern.
This interface provides a general visit function to dispatch different type of expression nodes to their specificvisit*
functions. Custom expression types that are unknown to Ktorm will be dispatched to visitUnknown.
For each expression type, there is a corresponding visit*
function in this interface; for SelectExpression, it’s
visitSelect; for TableExpression, it’s visitTable; and so on. Those functions generally accept an expression
instance of the specific type and dispatch the children nodes to their own visit*
functions. Finally, after all
children nodes are visited, the parent expression instance will be directly returned if no children are modified.
As SQL expressions are immutable, to modify an expression, we need to override a child visit*
function, and return
a new-created expression in it. Then its parent’s visit*
function will notice the change and create a new parent
expression using the modified child node returned by us. As the process is recursive, the ancestor nodes also returns
new-created instances. Finally, as a result of calling visit, a new expression tree will be returned with our
modifications applied.
SqlFormatter is a typical example used to format expressions as executable SQL strings.
Functions
Name | Summary |
---|---|
open fun visit(expr: SqlExpression): SqlExpression Dispatch different type of expression nodes to their specific | |
open fun <T : Any> visitAggregate( Function that visits an AggregateExpression. | |
open fun <T : Any> visitArgument( Function that visits an ArgumentExpression. | |
open fun visitBetween( Function that visits a BetweenExpression. | |
open fun <T : Any> visitBinary( Function that visits a BinaryExpression. | |
open fun <T : Any> visitCaseWhen( Function that visits a CaseWhenExpression. | |
open fun <T : Any> visitCasting( Function that visits a CastingExpression. | |
open fun <T : Any> visitColumn( Function that visits a ColumnExpression. | |
open fun <T : Any> visitColumnAssignment( Function that visits a ColumnAssignmentExpression. | |
open fun <T : Any> visitColumnDeclaring( Function that visits a ColumnDeclaringExpression. | |
open fun visitDelete( Function that visits a DeleteExpression. | |
open fun visitExists( Function that visits an ExistsExpression. | |
open fun <T : SqlExpression> visitExpressionList( Helper function for visiting a list of expressions. | |
open fun <T : Any> visitFunction( Function that visits a FunctionExpression. | |
open fun visitInList( Function that visits an InListExpression. | |
open fun visitInsert( Function that visits an InsertExpression. | |
open fun visitInsertFromQuery( Function that visits an InsertFromQueryExpression. | |
open fun visitJoin(expr: JoinExpression): JoinExpression Function that visits a JoinExpression. | |
open fun visitOrderBy( Function that visits an OrderByExpression. | |
open fun visitQuery(expr: QueryExpression): QueryExpression Function that visits a QueryExpression. | |
open fun visitQuerySource( Function that visits a QuerySourceExpression. | |
open fun <T : Any> visitScalar( Function that visits a general ScalarExpression, this function dispatches different type of scalar expressions | |
open fun visitSelect( Function that visits a SelectExpression. | |
open fun visitTable(expr: TableExpression): TableExpression Function that visits a TableExpression. | |
open fun <T : Any> visitUnary( Function that visits an UnaryExpression. | |
open fun visitUnion(expr: UnionExpression): UnionExpression Function that visits an UnionExpression. | |
open fun visitUnknown(expr: SqlExpression): SqlExpression Function that visits an unknown expression. | |
open fun visitUpdate( Function that visits an UpdateExpression. | |
open fun <T : Any> visitWhenClauses( Helper function for visiting when clauses of CaseWhenExpression. | |
open fun visitWindowFrameBound( Function that visits a WindowFrameBoundExpression. | |
open fun <T : Any> visitWindowFunction( Function that visits a WindowFunctionExpression. | |
open fun visitWindowSpecification( Function that visits a WindowSpecificationExpression. |
Extension Functions
Name | Summary |
---|---|
infix fun <T : Any> T.eq( Equal operator, translated to | |
infix fun <T : Any> T.neq( Not-equal operator, translated to | |
infix fun <T : Any> T.notEq( Not-equal operator, translated to |
Inheritors
Name | Summary |
---|---|
interface MySqlExpressionVisitor : SqlExpressionVisitor Base interface designed to visit or modify MySQL expression trees using visitor pattern. | |
interface PostgreSqlExpressionVisitor : SqlExpressionVisitor Base interface designed to visit or modify PostgreSQL expression trees using visitor pattern. | |
abstract class SqlFormatter : SqlExpressionVisitor Implementation of SqlExpressionVisitor, visiting SQL expression trees using visitor pattern. After a visit | |
interface SQLiteExpressionVisitor : SqlExpressionVisitor Base interface designed to visit or modify SQLite expression trees using visitor pattern. |