tortoise-orm
tortoise-orm copied to clipboard
Window Functions
Is your feature request related to a problem? Please describe. There doesn't exist any documentation on custom to builtin window frames within Tortoise ORM. Is this something that's implemented but not documented? I propose we implement this.
Describe the solution you'd like
from tortoise.functions import WindowFunction
class Lead(Function):
database_func = "lead"
func_args = [1]
over = [some_field, some_field]
order_by = [some_field, some_field]
sql = Task.all().annotate(my_field=Lead('created_at', '%Y-%m-%d')).sql()
Describe alternatives you've considered We could also try adding a RawSQL class that we can put inside annotate()
Task.all().annotate(end_date=RawSQL("LEAD(start_date, 1) OVER (ORDER BY star_date)"))