3

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?

1 Answer 1

3

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) 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.