From 3531a69aee3d92ae46607a8629b9d0ee7ceda76d Mon Sep 17 00:00:00 2001 From: Kacper Stasiuk Date: Mon, 1 Aug 2022 15:37:58 +0200 Subject: [PATCH] Add full outer join --- .../main/kotlin/org/ktorm/dsl/QuerySource.kt | 20 ++++++++++++++++++- .../org/ktorm/expression/SqlExpressions.kt | 7 ++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ktorm-core/src/main/kotlin/org/ktorm/dsl/QuerySource.kt b/ktorm-core/src/main/kotlin/org/ktorm/dsl/QuerySource.kt index e676137a..54acffa2 100644 --- a/ktorm-core/src/main/kotlin/org/ktorm/dsl/QuerySource.kt +++ b/ktorm-core/src/main/kotlin/org/ktorm/dsl/QuerySource.kt @@ -17,7 +17,11 @@ package org.ktorm.dsl import org.ktorm.database.Database -import org.ktorm.expression.* +import org.ktorm.expression.BinaryExpression +import org.ktorm.expression.BinaryExpressionType +import org.ktorm.expression.JoinExpression +import org.ktorm.expression.JoinType +import org.ktorm.expression.QuerySourceExpression import org.ktorm.schema.BaseTable import org.ktorm.schema.BooleanSqlType import org.ktorm.schema.ColumnDeclaring @@ -102,6 +106,20 @@ public fun QuerySource.rightJoin(right: BaseTable<*>, on: ColumnDeclaring, on: ColumnDeclaring? = null): QuerySource { + return this.copy( + expression = JoinExpression( + type = JoinType.FULL_OUTER_JOIN, + left = expression, + right = right.asExpression(), + condition = on?.asExpression() + ) + ) +} + /** * Return a new-created [Query] object, left joining all the reference tables, and selecting all columns of them. */ diff --git a/ktorm-core/src/main/kotlin/org/ktorm/expression/SqlExpressions.kt b/ktorm-core/src/main/kotlin/org/ktorm/expression/SqlExpressions.kt index 2f06186f..4dc581a8 100644 --- a/ktorm-core/src/main/kotlin/org/ktorm/expression/SqlExpressions.kt +++ b/ktorm-core/src/main/kotlin/org/ktorm/expression/SqlExpressions.kt @@ -412,7 +412,12 @@ public enum class JoinType(private val value: String) { /** * Right join, translated to the `right join` keyword in SQL. */ - RIGHT_JOIN("right join"); + RIGHT_JOIN("right join"), + + /** + * Full outer join, translated to the `full outer join` keyword in SQL. + */ + FULL_OUTER_JOIN("full outer join"); override fun toString(): String { return value