Skip to content

Commit

Permalink
GH-81 Modify join slices
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Nov 8, 2024
1 parent cc08be0 commit 072083c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions sqiffy/src/main/kotlin/com/dzikoysk/sqiffy/dsl/Expression.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ sealed interface Expression<SOURCE, RESULT>

sealed interface Condition<SOURCE> : Expression<SOURCE, Boolean>

/* Const expressions */

class ConstExpression<T>(val value: T) : Expression<T, T>

fun const(value: String): ConstExpression<String> = ConstExpression(value)

/* Math operators */

enum class MathOperator(val symbol: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ open class SelectStatement(
val join = Join(type, table, mappedConditions.map { JoinCondition(on = it.first, toExpression = it.second) })
require(!joins.contains(join)) { "Join $join is already defined" }
joins.add(join)
slice.addAll(joinedToColumns.flatMap { it.table.getColumns() })
slice.addAll(table.getColumns())
}

fun slice(vararg selectables: Selectable): SelectStatement = also {
Expand All @@ -100,6 +100,14 @@ open class SelectStatement(
this.slice = selectables.toMutableList()
}

fun extendSlice(vararg selectables: Selectable): SelectStatement = also {
this.slice.addAll(selectables)
}

fun extendSlice(selectables: Collection<Selectable>): SelectStatement = also {
this.slice.addAll(selectables)
}

fun where(where: () -> Expression<out Column<*>, Boolean>): SelectStatement = also {
require(this.where == null) { "Where clause is already defined" }
this.where = where()
Expand Down

0 comments on commit 072083c

Please sign in to comment.