Replies: 1 comment 4 replies
-
I think having an To begin, can you open a PR and add more doc test examples? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, a lot of "operator" methods are duplicated across
Expr
,SimpleExpr
andsea_orm::ColumnTrait
, but the list of methods is slightly different for each. The type conversions are also messy and non-obvious. I complained about this in #770 today. Writing generic code on top is especially difficult.I'd really like to:
Expr
/SimpleExpr
divideExprTrait
???) and reuse it for SeaORM columns (ColumnTrait: ExprTrait
???)I understand that this is a big change that won't happen soon (especially with SeaORM 1.0 on the horizon). But still, let's discuss this possibility
UPDATE: as I think about it,
ExprTrait
should be implemented for all expression types (T: Into<SimpleExpr>
), rather than justExpr
andSimpleExpr
. I.e., including the "lower-level" ones like Value and FunctionCall (see #770).UPDATE 2024-07-06: I'd like
ExprTrait
binary operator methods to accept anInto<SimpleExpr>
parameter (like in Expr::eq), rather thanInto<Value>
(like in ColumnTrait::eq). Currently, when I want to compare a SeaORM column with an expr which isn't a column or a value (e.g. Expr::cust), I have to wrap the column in Expr::col like this:Expr::col(my_column).eq(Expr::cust(...))
. It's verbose and very unintuitive.And to add another example of the current everyday pain without
ExprTrait
. When I needed to expressExpr::cust(...).lte(rust_value)
, I couldn't do that in a straightforward way. Expr::cust returns a SimpleExpr, which doesn't have anlte
method. It only has eq and ne. There's Expr::lte, but it requires the left side to be an Expr. And I couldn't find a way to convert fromSimpleExpr
toExpr
. Eventually, I came up with this workaround:Expr::cust(...).binary(BinOper::SmallerThanOrEqual, rust_value)
. Now, as I was typing this and double-checking everything, I finally foud Expr::expr which allows me to writeExpr::expr(Expr::cust(...)).lte(rust_value)
. But it's still not the prettiest solution and definitely not intuitive/discoverable. Btw, I really don't understand why you couldn't justimpl From<SimpleExpr> for Expr
instead of defining this random inherent method which I couldn't even find among 58 other inherent methods. These type conversions and unintuitive APIs really drive me mad from time to time, and this is what sparked the idea ofExprTrait
.Sorry for this little rant, I still appreciate the work done on SeaORM. And I still hope to do an initial PR with
ExprTrait
when I have time/courage for larger open source PRs that aren't adding features required by the business.UPDATE 2024-07-07: here's the first PR with
ExprTrait
: #791 🚀I've listed some of my further plans there.
Based on that work, now I'm pretty sure that Expr indeed shouldn't be a type. It seems like just a namespace for static SimpleExpr constructors! I'll see what I can do while minimizing breakage. I hope to turn one into a type alias of another. This should be possible, because there are no conflicting methods and all Expr fields are private.
UPDATE 2025-03-31:
sea_orm
: Wanted breaking changes in `sea_orm` sea-orm#2548UPDATE 2025-04-02: Using
ExprTrait
to reduce the boilerplate in the codebase and docs:Expr::expr
from docs and internal code #873Expr::expr
from internal code sea-orm#2554UPDATE 2025-05-22:
Expr
andSimpleExpr
#888UPDATE 2025-05-28: We've successfully unified
Expr
andSimpleExpr
! The change will be released insea_query 1.0
andsea_orm 2.0
:Expr
andSimpleExpr
as one type #889UPDATE 2025-06-01: Almost done deleting inherent
SimpleExpr
methods!SimpleExpr
methods that duplicateExprTrait
#890ExprTrait
sea-orm#2606UPDATE 2025-06-08: There are only two other remaining tasks to do.
ColumnTrait: Into<SimpleExpr>
and delete the old "operator" methods fromColumnTrait
ActiveEnum: Into<SimpleExpr>
See SeaQL/sea-orm#2548 for the rationale and status.
Beta Was this translation helpful? Give feedback.
All reactions