Skip to content

Commit

Permalink
Merge pull request #781 from jeffgbutler/array-methods
Browse files Browse the repository at this point in the history
Add Array Based Methods to Kotlin DSL
  • Loading branch information
jeffgbutler authored Apr 23, 2024
2 parents ad48f44 + 2a8bda0 commit 544aaf7
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ types - which is a rare usage. Please let us know if this causes an undo hardshi
as rendering empty lists). This change should be transparent to users unless they have implemented custom conditions.
4. Added a configuration setting to allow empty list conditions to render. This could generate invalid SQL, but might be
a good safety measure in some cases.
5. Added Array based functions for the "in" and "not in" conditions in the Kotlin DSL. These functions allow a more
natural use of an Array as an input for an "in" condition. They also allow easy reuse of a vararg argument in a
function. ([#781](https://github.com/mybatis/mybatis-dynamic-sql/pull/781))

## Release 1.5.0 - April 21, 2023

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ open class GroupingCriteriaCollector : SubCriteriaCollector() {

fun <T> BindableColumn<T>.isIn(vararg values: T & Any) = isIn(values.asList())

@JvmName("isInArray")
infix fun <T> BindableColumn<T>.isIn(values: Array<out T & Any>) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isIn(values))

infix fun <T> BindableColumn<T>.isIn(values: Collection<T & Any>) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isIn(values))

Expand All @@ -325,11 +329,19 @@ open class GroupingCriteriaCollector : SubCriteriaCollector() {

fun <T> BindableColumn<T>.isInWhenPresent(vararg values: T?) = isInWhenPresent(values.asList())

@JvmName("isInArrayWhenPresent")
infix fun <T> BindableColumn<T>.isInWhenPresent(values: Array<out T?>?) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent(values))

infix fun <T> BindableColumn<T>.isInWhenPresent(values: Collection<T?>?) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInWhenPresent(values))

fun <T> BindableColumn<T>.isNotIn(vararg values: T & Any) = isNotIn(values.asList())

@JvmName("isNotInArray")
infix fun <T> BindableColumn<T>.isNotIn(values: Array<out T & Any>) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotIn(values))

infix fun <T> BindableColumn<T>.isNotIn(values: Collection<T & Any>) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotIn(values))

Expand All @@ -338,6 +350,10 @@ open class GroupingCriteriaCollector : SubCriteriaCollector() {

fun <T> BindableColumn<T>.isNotInWhenPresent(vararg values: T?) = isNotInWhenPresent(values.asList())

@JvmName("isNotInArrayWhenPresent")
infix fun <T> BindableColumn<T>.isNotInWhenPresent(values: Array<out T?>?) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent(values))

infix fun <T> BindableColumn<T>.isNotInWhenPresent(values: Collection<T?>?) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInWhenPresent(values))

Expand Down Expand Up @@ -394,24 +410,40 @@ open class GroupingCriteriaCollector : SubCriteriaCollector() {

fun BindableColumn<String>.isInCaseInsensitive(vararg values: String) = isInCaseInsensitive(values.asList())

@JvmName("isInArrayCaseInsensitive")
infix fun BindableColumn<String>.isInCaseInsensitive(values: Array<out String>) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInCaseInsensitive(values))

infix fun BindableColumn<String>.isInCaseInsensitive(values: Collection<String>) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInCaseInsensitive(values))

fun BindableColumn<String>.isInCaseInsensitiveWhenPresent(vararg values: String?) =
isInCaseInsensitiveWhenPresent(values.asList())

@JvmName("isInArrayCaseInsensitiveWhenPresent")
infix fun BindableColumn<String>.isInCaseInsensitiveWhenPresent(values: Array<out String?>?) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInCaseInsensitiveWhenPresent(values))

infix fun BindableColumn<String>.isInCaseInsensitiveWhenPresent(values: Collection<String?>?) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isInCaseInsensitiveWhenPresent(values))

fun BindableColumn<String>.isNotInCaseInsensitive(vararg values: String) =
isNotInCaseInsensitive(values.asList())

@JvmName("isNotInArrayCaseInsensitive")
infix fun BindableColumn<String>.isNotInCaseInsensitive(values: Array<out String>) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInCaseInsensitive(values))

infix fun BindableColumn<String>.isNotInCaseInsensitive(values: Collection<String>) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInCaseInsensitive(values))

fun BindableColumn<String>.isNotInCaseInsensitiveWhenPresent(vararg values: String?) =
isNotInCaseInsensitiveWhenPresent(values.asList())

@JvmName("isNotInArrayCaseInsensitiveWhenPresent")
infix fun BindableColumn<String>.isNotInCaseInsensitiveWhenPresent(values: Array<out String?>?) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInCaseInsensitiveWhenPresent(values))

infix fun BindableColumn<String>.isNotInCaseInsensitiveWhenPresent(values: Collection<String?>?) =
invoke(org.mybatis.dynamic.sql.util.kotlin.elements.isNotInCaseInsensitiveWhenPresent(values))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,24 +262,36 @@ fun <T> isLessThanOrEqualToWhenPresent(value: T?): IsLessThanOrEqualTo<T> =

fun <T> isIn(vararg values: T & Any): IsIn<T> = isIn(values.asList())

@JvmName("isInArray")
fun <T> isIn(values: Array<out T & Any>): IsIn<T> = SqlBuilder.isIn(values.asList())

fun <T> isIn(values: Collection<T & Any>): IsIn<T> = SqlBuilder.isIn(values)

fun <T> isIn(subQuery: KotlinSubQueryBuilder.() -> Unit): IsInWithSubselect<T> =
SqlBuilder.isIn(KotlinSubQueryBuilder().apply(subQuery))

fun <T> isInWhenPresent(vararg values: T?): IsIn<T> = isInWhenPresent(values.asList())

@JvmName("isInArrayWhenPresent")
fun <T> isInWhenPresent(values: Array<out T?>?): IsIn<T> = SqlBuilder.isInWhenPresent(values?.asList())

fun <T> isInWhenPresent(values: Collection<T?>?): IsIn<T> = SqlBuilder.isInWhenPresent(values)

fun <T> isNotIn(vararg values: T & Any): IsNotIn<T> = isNotIn(values.asList())

@JvmName("isNotInArray")
fun <T> isNotIn(values: Array<out T & Any>): IsNotIn<T> = SqlBuilder.isNotIn(values.asList())

fun <T> isNotIn(values: Collection<T & Any>): IsNotIn<T> = SqlBuilder.isNotIn(values)

fun <T> isNotIn(subQuery: KotlinSubQueryBuilder.() -> Unit): IsNotInWithSubselect<T> =
SqlBuilder.isNotIn(KotlinSubQueryBuilder().apply(subQuery))

fun <T> isNotInWhenPresent(vararg values: T?): IsNotIn<T> = isNotInWhenPresent(values.asList())

@JvmName("isNotInArrayWhenPresent")
fun <T> isNotInWhenPresent(values: Array<out T?>?): IsNotIn<T> = SqlBuilder.isNotInWhenPresent(values?.asList())

fun <T> isNotInWhenPresent(values: Collection<T?>?): IsNotIn<T> = SqlBuilder.isNotInWhenPresent(values)

fun <T> isBetween(value1: T & Any): BetweenBuilder<T & Any> = BetweenBuilder(value1)
Expand Down Expand Up @@ -318,22 +330,37 @@ fun isNotLikeCaseInsensitiveWhenPresent(value: String?): IsNotLikeCaseInsensitiv

fun isInCaseInsensitive(vararg values: String): IsInCaseInsensitive = isInCaseInsensitive(values.asList())

@JvmName("isInArrayCaseInsensitive")
fun isInCaseInsensitive(values: Array<out String>): IsInCaseInsensitive = SqlBuilder.isInCaseInsensitive(values.asList())

fun isInCaseInsensitive(values: Collection<String>): IsInCaseInsensitive = SqlBuilder.isInCaseInsensitive(values)

fun isInCaseInsensitiveWhenPresent(vararg values: String?): IsInCaseInsensitive =
isInCaseInsensitiveWhenPresent(values.asList())

@JvmName("isInArrayCaseInsensitiveWhenPresent")
fun isInCaseInsensitiveWhenPresent(values: Array<out String?>?): IsInCaseInsensitive =
SqlBuilder.isInCaseInsensitiveWhenPresent(values?.asList())

fun isInCaseInsensitiveWhenPresent(values: Collection<String?>?): IsInCaseInsensitive =
SqlBuilder.isInCaseInsensitiveWhenPresent(values)

fun isNotInCaseInsensitive(vararg values: String): IsNotInCaseInsensitive = isNotInCaseInsensitive(values.asList())

@JvmName("isNotInArrayCaseInsensitive")
fun isNotInCaseInsensitive(values: Array<out String>): IsNotInCaseInsensitive =
SqlBuilder.isNotInCaseInsensitive(values.asList())

fun isNotInCaseInsensitive(values: Collection<String>): IsNotInCaseInsensitive =
SqlBuilder.isNotInCaseInsensitive(values)

fun isNotInCaseInsensitiveWhenPresent(vararg values: String?): IsNotInCaseInsensitive =
isNotInCaseInsensitiveWhenPresent(values.asList())

@JvmName("isNotInArrayCaseInsensitiveWhenPresent")
fun isNotInCaseInsensitiveWhenPresent(values: Array<out String?>?): IsNotInCaseInsensitive =
SqlBuilder.isNotInCaseInsensitiveWhenPresent(values?.asList())

fun isNotInCaseInsensitiveWhenPresent(values: Collection<String?>?): IsNotInCaseInsensitive =
SqlBuilder.isNotInCaseInsensitiveWhenPresent(values)

Expand Down
13 changes: 7 additions & 6 deletions src/site/markdown/docs/kotlinWhereClauses.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ where clauses with and/or/not phrases. See the following example of a complex wh
select(foo) {
from(bar)
where {
id isEqualTo 3
and { id isEqualTo 4 }
id isEqualTo 3
or { id isEqualTo 4 }
and { not { id isEqualTo 6 } }
}
or { id isEqualTo 4 }
and { not { id isEqualTo 6 } }
}
```

Expand Down Expand Up @@ -215,8 +214,10 @@ These criteria should be updated by moving the column and condition into a lambd
```kotlin
select(foo) {
from(bar)
where { id isEqualTo 3 }
or { id isEqualTo 4 }
where {
id isEqualTo 3
or { id isEqualTo 4 }
}
}
```

Expand Down
Loading

0 comments on commit 544aaf7

Please sign in to comment.