Unfortunately, Tortoise ORM processes different queries differently.
For instance:
- for
update
query you can use just a string value:
await User.filter(id=user_id).update(updated_at="now()")
- for
filter
queries you can use pypika.functions
and pypika.terms
For instance:
from pypika.terms import Parameter, Interval
await User.filter(created_at__gte=Parameter("CURRENT_DATE") - Interval(days=30))
- for
create
queries it's very tricky. Tortoise ORM is not built for that and what you need to do is to make your own field type class by inheriting from tortoise.fields.data.DateField
or tortoise.fields.data.DateTimeField
and override to_db_value
method.
Long story short, it is possible but very tricky, especially if you want to use all 3 types of queries: CREATE, UPDATE and SELECT.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…