English | 简体中文

api-docs / org.ktorm.expression / SqlExpressionVisitor

SqlExpressionVisitor

open class SqlExpressionVisitor (source code)

Base class designed to visit or modify SQL expression trees using visitor pattern.

This class provides a general visit function to dispatch different type of expression nodes to the specific
visit* 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 class; 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.

To modify an expression tree, we need to override a visit* function, and return a new-created expression in it.
Then the parent’s visit* function will detect it and create a new parent expression using the modified child node
returned by us. That’s recursive, so the ancestor nodes also returns new-created instances. Finally, when we call
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.

Constructors

NameSummary

<init>

SqlExpressionVisitor()

Base class designed to visit or modify SQL expression trees using visitor pattern.

Functions

NameSummary

visit

open fun visit(expr: SqlExpression): SqlExpression

Dispatch different type of expression nodes to the specific visit* functions. Custom expression types that
are unknown to Ktorm will be dispatched to visitUnknown.

visitAggregate

open fun <T : Any> visitAggregate(
    expr: AggregateExpression<T>
): AggregateExpression<T>

visitArgument

open fun <T : Any> visitArgument(
    expr: ArgumentExpression<T>
): ArgumentExpression<T>

visitBetween

open fun <T : Any> visitBetween(
    expr: BetweenExpression<T>
): BetweenExpression<T>

visitBinary

open fun <T : Any> visitBinary(
    expr: BinaryExpression<T>
): BinaryExpression<T>

visitCasting

open fun <T : Any> visitCasting(
    expr: CastingExpression<T>
): CastingExpression<T>

visitColumn

open fun <T : Any> visitColumn(
    expr: ColumnExpression<T>
): ColumnExpression<T>

visitColumnAssignment

open fun <T : Any> visitColumnAssignment(
    expr: ColumnAssignmentExpression<T>
): ColumnAssignmentExpression<T>

visitColumnAssignments

open fun visitColumnAssignments(
    original: List<ColumnAssignmentExpression<*>>
): List<ColumnAssignmentExpression<*>>

visitColumnDeclaring

open fun <T : Any> visitColumnDeclaring(
    expr: ColumnDeclaringExpression<T>
): ColumnDeclaringExpression<T>

visitColumnDeclaringList

open fun visitColumnDeclaringList(
    original: List<ColumnDeclaringExpression<*>>
): List<ColumnDeclaringExpression<*>>

visitDelete

open fun visitDelete(
    expr: DeleteExpression
): DeleteExpression

visitExists

open fun visitExists(
    expr: ExistsExpression
): ExistsExpression

visitExpressionList

open fun <T : SqlExpression> visitExpressionList(
    original: List<T>,
    subVisitor: (T) -> T = { visit(it) as T }
): List<T>

visitFunction

open fun <T : Any> visitFunction(
    expr: FunctionExpression<T>
): FunctionExpression<T>

visitGroupByList

open fun visitGroupByList(
    original: List<ScalarExpression<*>>
): List<ScalarExpression<*>>

visitInList

open fun <T : Any> visitInList(
    expr: InListExpression<T>
): InListExpression<T>

visitInsert

open fun visitInsert(
    expr: InsertExpression
): InsertExpression

visitInsertFromQuery

open fun visitInsertFromQuery(
    expr: InsertFromQueryExpression
): InsertFromQueryExpression

visitJoin

open fun visitJoin(expr: JoinExpression): JoinExpression

visitOrderBy

open fun visitOrderBy(
    expr: OrderByExpression
): OrderByExpression

visitOrderByList

open fun visitOrderByList(
    original: List<OrderByExpression>
): List<OrderByExpression>

visitQuery

open fun visitQuery(expr: QueryExpression): QueryExpression

visitQuerySource

open fun visitQuerySource(
    expr: QuerySourceExpression
): QuerySourceExpression

visitScalar

open fun <T : Any> visitScalar(
    expr: ScalarExpression<T>
): ScalarExpression<T>

visitSelect

open fun visitSelect(
    expr: SelectExpression
): SelectExpression

visitTable

open fun visitTable(expr: TableExpression): TableExpression

visitUnary

open fun <T : Any> visitUnary(
    expr: UnaryExpression<T>
): UnaryExpression<T>

visitUnion

open fun visitUnion(expr: UnionExpression): UnionExpression

visitUnknown

open fun visitUnknown(expr: SqlExpression): SqlExpression

visitUpdate

open fun visitUpdate(
    expr: UpdateExpression
): UpdateExpression

Inheritors

NameSummary

MySqlExpressionVisitor

open class MySqlExpressionVisitor : SqlExpressionVisitor

Base class designed to visit or modify MySQL’s expression trees using visitor pattern.

PostgreSqlExpressionVisitor

open class PostgreSqlExpressionVisitor : SqlExpressionVisitor

Base class designed to visit or modify PostgreSQL’s expression trees using visitor pattern.

SqlFormatter

abstract class SqlFormatter : SqlExpressionVisitor

Subclass of SqlExpressionVisitor, visiting SQL expression trees using visitor pattern. After the visit completes,
the executable SQL string will be generated in the sql property with its execution parameters in parameters.