Hi I'm trying to use CASE WHEN THEN ELSE in tortoise-orm. I tried the following but didn't work:
import datetime
import tortoise.models
import tortoise.fields
import tortoise.expressions
from pypika import Case
class Task(tortoise.models.Model):
uid = tortoise.fields.UUIDField(pk=True)
name = tortoise.fields.CharField(255)
name_updated_at = tortoise.fields.data.DatetimeField(auto_now_add=True, null=False)
await Task.filter(uid="my-super-uid").update(
name=Case()
.when(tortoise.expressions.F('name_updated_at') > datetime.datetime.utcnow(), "Hi")
.else_(tortoise.expressions.F('name'))
)
I know CASE is supported by pypika, but I don't know how to use it in tortoise-orm.
Also I do want to use CASE because I want to use cases for multiple fields in a single update, instead of making multiple updates with different filter(...) parameters.
Any idea how to use CASE()??