-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add Expr in_tuples and custom #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Export SqlWriterValues publicly - Add Select::to_values() returning SqlWriterValues - PG placeholder style: , , ...
- Add Expr::Custom to well_known_no_parentheses (no extra parens) - select_37a: nested NOT expressions with TRUE/FALSE
- Change from Expr::custom to Expr::value(true/false) - SQL generated: OR with collected values - Demonstrates pqb's aggressive parameterization vs sea-query's inline
- select_44: NOT with single condition - select_45: NOT with OR - select_46: NOT with AND semantics - select_47: NOT with AND compound - select_48: Tuple comparison - select_49: SELECT * with asterisk
| pub fn in_tuples<T, I>(self, tuples: I) -> Expr | ||
| where | ||
| T: IntoIterator<Item = Expr>, | ||
| I: IntoIterator<Item = T>, | ||
| { | ||
| self.binary( | ||
| BinaryOp::In, | ||
| Expr::Tuple( | ||
| tuples | ||
| .into_iter() | ||
| .map(|t| Expr::Tuple(t.into_iter().collect())) | ||
| .collect(), | ||
| ), | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed sea-query has ValueTuple and ValueTupleIter design, but I wonder if they are over-designed or can be replaced with SmallVec<Value; 3>.
@Huliiiiii could you share some background why you introduce ValueTuple in sea-query?
FYI, pqb is a fork of sea-query to trim down code for dedicated PG query builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no specific reason. We chose not to replace it with smallvec in 1.0 mainly to maintain compatibility.
| Select::new() | ||
| .column("id") | ||
| .from("glyph") | ||
| .and_where(Expr::tuple([Expr::column("aspect"), Expr::value("100")]).in_tuples([[Expr::value(8), Expr::value("100")]])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that IntoValueTuple and ValueTuple are to help write code like:
.in_tuples([(8, "100)])
rather than:
.in_tuples([[Expr::value(8), Expr::value("100")]]))
But Expr::tuple already has the same short-coming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave it as further improvement if we do find it very helpful.
No description provided.