'IN clause with jooq and kotlin
I have the following code which works fine:
fun <T> createComparisonOperator(field: Field<T>, value: T, op: String): Condition {
return when(op) {
"eq" -> field.eq(DSL.inline(value))
else -> throw Exception("No Op)
}
}
Now what I want to do is test for membership in an array and I do something like:
fun<T> createMembershipOperator(field: Field<T>, value: Collection<T>, op: String): Condition {
return when(op) {
"in" -> field.`in`(DSL.inline(value))
else -> throw Exception("No op")
}
}
The membership test is called as:
val wrappedValue = listOf("100")
val sqlField = DSL.field(column, SQLDataType.VARCHAR)
return createMembershipOperator<String>(sqlField, wrappedValue, op)
It does not fail but does not return any data.
Solution 1:[1]
Write this:
"in" -> field.`in`(value.map(DSL::inline))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lukas Eder |
