10

I want to define a column of type date. This column should hold the current date of the resource created. How do i set this up? I'm new to kotlin.

In python, one would impletement it this way: date_created = db.Column(db.DateTime, default=db.func.current_timestamp())

What's the kotlin equivalent?

edoc
  • 179
  • 3
  • 9

1 Answers1

22

If you want to just have a datetime column with a default value which will be evaluated on insert of a new record please use defaultExpression function:

object YourTable : IntIdTable() {
   val dateCreated = datetime("date_created").defaultExpression(CurrentDateTime)
}

If you want to generate datetime value on the client side:

object YourTable : IntIdTable() {
   val dateCreated = datetime("date_created").clientDefault{ DateTime.now() }
}
Tapac
  • 1,889
  • 1
  • 14
  • 18