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
-
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
EDIT: Some other types that would benefit from implementing
ExprTrait
: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.
Beta Was this translation helpful? Give feedback.
All reactions