Up
03/28/2026, 1:51 PMclientDefault() but it should be doable with defaultExpression() too I think.
datetime("expires_at").clientDefault { (Clock.System.now() + 5.minutes).toLocalDateTime(TimeZone.UTC) }Chantal Loncle
03/31/2026, 3:26 PMDEFAULT (TIMESTAMPADD(MINUTE, 5, NOW())) NOT NULL
If you're using PostgreSQL, maybe this is what you want:
DEFAULT NOW() + INTERVAL '5 MINUTE' NOT NULL
The following example shows how you could generate this SQL:
// Exposed provides CURRENT_TIMESTAMP()
// so this is only if you would prefer NOW() specifically
object NowDateTime : Function<LocalDateTime>(KotlinLocalDateTimeColumnType()) {
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
queryBuilder { +"NOW()" }
}
}
class AddTs(
val expr: Expression<LocalDateTime>,
val interval: Int,
val unit: DateTimeUnit,
) : Function<LocalDateTime>(KotlinLocalDateTimeColumnType()) {
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
queryBuilder {
// simplify to the exact db & SQL function you need
when (currentDialect) {
is MysqlDialect -> {
+"TIMESTAMPADD("
append("$unit, $interval, ", expr)
+")"
}
is PostgreSQLDialect -> {
append(expr, " + INTERVAL ")
append("'$interval $unit'")
}
else -> error("Not implemented")
}
}
}
}
fun ExpressionWithColumnType<LocalDateTime>.plus(
interval: Int,
unit: DateTimeUnit,
) = AddTs(this, interval, unit)
// example usage
val expiresAt = datetime("expires_at")
.defaultExpression(NowDateTime.plus(5, DateTimeUnit.MINUTE))Up
03/31/2026, 6:08 PM