How can I apply NOW() along with Exposed DAO

Viewed 66

I have such a table.

object AsdTable : IntIdTable("asd") {
    val created_date = timestamp("created_date")
    val code = varchar("code", 64)
}

And I'd like to build sql insert statement like INSERT INTO asd(created_date, code) VALUES(NOW(), ??) Kotlin code is

transaction {
  AsdEntity.new {
    createdDate = ?
    code = "oook"
  }
}

How this can be achieved?

1 Answers

I managed to make it work via defaultExpression:

object AsdTable : IntIdTable("asd") {
    val created_date = timestamp("created_date").defaultExpression(CurrentTimestamp())
    val code = varchar("code", 64)
}

transaction {
  AsdEntity.new {
    code = "OK"
  }
}

NOW() or CURRENT_TIMESTAMP() is generated within INSERT statement.

Related