I have a table that has two fields of type Datetime and int.
object DummyTable : IntIdTable("db.table", columnName = "id") {
val createdAt = datetime("created_at")
val mins = integer("mins")
override val primaryKey = PrimaryKey(id)
}
I have a function where i want to check the condition that createdAt plus mins is less than the Datetime now.
fun isValid(id: String): String? {
return DummyTable.select{
COND??
}.single()[DummyTable.age]
}
Something like this:
DummyTable.createdAt plus minutes lessEq DateTime.now()??
What would be the query condition?
I thought that the answer on github was enough.
class DateAddMins(val dateExp: Expression<DateTime>, val addMins: Expression<Int?>) : Expression<DateTime>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
append("DATE_ADD(", dateExp, ", INTERVAL IFNULL(", addMins, ", 0) MINUTE)")
}
}
DummyTable.select {
DateAddMins(DummyTable.createdAt, DummyTable.mins) lessEq DateTime.now)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With