Luca
Luca

Reputation: 10996

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.

Upvotes: 1

Views: 192

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220952

Write this:

"in" -> field.`in`(value.map(DSL::inline))

Upvotes: 1

Related Questions