https://kotlinlang.org logo
#exposed
Title
# exposed
n

Nate Mara

03/15/2018, 10:54 PM
Hello, I'm new to Kotlin and Exposed, and I'm having some difficulty with the DAO api. I'm trying to create a function that will have a where clause that is different depending on runtime user input. I don't appear to be able to use any if blocks inside the transaction block. I'm trying to do something like this:
Copy code
fun findX(xGt: BigDecimal?, xLt: BigDecimal?): List<DaoClass> {
    return transaction {
        DaoClass.find {
            var condition = TableClass.any()
            if (xGt != null) {
                condition = condition.and(TableClass.x.greater(xGt))
            }
            if (xLt != null) {
                condition = condition.and(TableClass.x.less(xGt))
            }

            condition
        }.toList()
    }
}
Is this possible?
t

tapac

03/16/2018, 6:44 AM
You can replace
TableClass.any()
with
TableClass.id.isNotNull()