Skip to content

Commit

Permalink
Add Concat function support. Fixes JetBrains#509
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdi13 committed Mar 15, 2019
1 parent 06dd75d commit 4122071
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exposed/src/main/kotlin/org/jetbrains/exposed/sql/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ class GroupConcat<T : String?>(
override fun toSQL(queryBuilder: QueryBuilder): String
= currentDialect.functionProvider.groupConcat(this, queryBuilder)
}

class Concat<T>(val expr: Expression<*>, vararg val items: String) : Function<T?>(VarCharColumnType()) {
override fun toSQL(queryBuilder: QueryBuilder): String = currentDialect.functionProvider.concat(expr, queryBuilder, *items)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ fun <T : String?> Expression<T>.groupConcat(separator: String? = null, distinct:
fun <T : String?> Expression<T>.groupConcat(separator: String? = null, distinct: Boolean = false, orderBy: Array<Pair<Expression<*>,SortOrder>> = emptyArray()): GroupConcat<T> =
GroupConcat(this, separator, distinct, *orderBy)

fun <T : String?> Column<T>.concat(vararg items: String): Concat<T> =
Concat(this, *items)

object SqlExpressionBuilder {
fun <T, S:T?, E:ExpressionWithColumnType<S>, R:T> coalesce(expr: E, alternate: ExpressionWithColumnType<out T>) : ExpressionWithColumnType<R> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ abstract class FunctionProvider {
append(")")
}

open fun concat(expr: Expression<*>, builder: QueryBuilder, vararg items: String) =
"CONCAT(${expr.toSQL(builder)} , '${items.joinToString(" ,")}')"

interface MatchMode {
fun mode() : String
}
Expand Down

0 comments on commit 4122071

Please sign in to comment.