# exposed

Allan Galarza

05/10/2022, 4:08 PM
SOLVED: Answer in thread Is there a way to increase a timestamp field by a certain duration? SQL:
Copy code
UPDATE server_premium
    SET expiration = expiration + $1
    WHERE server_id = $2
    RETURNING expiration
Where $1 is a python timedelta, that was converted to a Postgresql Interval I'm trying to figure out how to do it in exposed.
I don't know if this is the best way, but it worked 😬
Copy code
fun Column<Instant?>.plusDuration(duration: Duration): CustomOperator<Instant> {
    val intervalExpression = object : Expression<Instant>() {
        override fun toQueryBuilder(queryBuilder: QueryBuilder) =
            queryBuilder { +"INTERVAL '${duration.inWholeSeconds} seconds'" }
    return CustomOperator("+", columnType, this, intervalExpression)
With this now I can update the value like:
Copy code
it[expiration] = expiration.plusDuration(days.days)