Closed henadzit closed 2 weeks ago
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
tortoise/backends/base/executor.py | 13 | 14 | 92.86% | ||
tortoise/expressions.py | 139 | 141 | 98.58% | ||
<!-- | Total: | 216 | 219 | 98.63% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
tortoise/queryset.py | 1 | 94.47% | ||
tortoise/backends/base/executor.py | 1 | 91.35% | ||
<!-- | Total: | 2 | --> |
Totals | |
---|---|
Change from base Build 11660093686: | 0.09% |
Covered Lines: | 6084 |
Relevant Lines: | 6709 |
Description
This PR:
F()
, e.g.F("author__name")
that automatically introduces joins to the queryF()
, e.g.IntFields.annotate(intnum_plus_1=F("intnum") + 1).annotate(intnum_plus_2=F("intnum_plus_1") + 1)
In order to achieve that, the following implementation details changed
Expression.resolve
was unified to always return aResolveResult
. Previously it could have been either a tuple or dictionary.F
was changed to be anExpression
instead of pypika'sField
. This allowed to move theF
's resolution code insideF.resolve
and simplify the resolution code in general becauseF
can be treated as otherExpression
s.CombinedExpression
was introduced to handle arithmetic operations onF()
, e.g.F("a") + 1
. It was inspired by Django's CombinedExpression and replaces pypika's arithmetic.CombinedExpression
is a child ofExpression
, so it can be resolved without knowing the exact type of the object as opposed to pypika'sArithmeticExpression
that was used previosly.As part of this PR, I had to change how custom functions can be defined. It changed from
to
Effectively now custom functions are supposed to be a tortoise
Function
, not a Pypika'sFunction
. The change had to be done because the Pypika'sFunction
is no longer compatible withF
and, frankly, having the interface that accepts both Pypika's functions and tortoise functions is a bit messy and makes the code quite convoluted.Motivation and Context
This introduces functionality supported by Django but also there is a clear demand for these features in the tortoise community. The following issues should be fixed by this PR
How Has This Been Tested?
Checklist: