Skip to content

Commit

Permalink
feat: utility leftJoin/rightJoin/innerJoin functions on top of the join
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Oct 11, 2024
1 parent a98705d commit ae57f26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ internal abstract class DslE2ETest(

val joinedData = database.select(UserTable)
.distinct()
.join(INNER, UserTable.id, GuildTable.owner)
.innerJoin(UserTable.id, GuildTable.owner)
.slice(UserTable.name, GuildTable.name)
.where { GuildTable.owner eq insertedGuild.owner }
.limit(1, offset = 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("MemberVisibilityCanBePrivate", "unused")

package com.dzikoysk.sqiffy.dsl.statements

import com.dzikoysk.sqiffy.SqiffyDatabase
Expand Down Expand Up @@ -57,6 +59,15 @@ open class SelectStatement(
this.distinct = true
}

fun <T> leftJoin(on: Column<T>, to: Column<T>): SelectStatement =
join(type = JoinType.LEFT, on = on, to = to)

fun <T> innerJoin(on: Column<T>, to: Column<T>): SelectStatement =
join(type = JoinType.INNER, on = on, to = to)

fun <T> rightJoin(on: Column<T>, to: Column<T>): SelectStatement =
join(type = JoinType.RIGHT, on = on, to = to)

fun <T> join(type: JoinType, on: Column<T>, to: Column<T>): SelectStatement = also {
val join = Join(type, on, to)
require(!joins.contains(join)) { "Join $join is already defined" }
Expand Down

0 comments on commit ae57f26

Please sign in to comment.