-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Feature flag to have more parentheses #723
Conversation
046fea6
to
677bc91
Compare
Interesting choice, why the runtime option? I think a compilation option is enough? |
Yes I considered that, but it's a bigger change to user code as well. If we add a new builder API ( |
Only if we think we will need other options in the future. My ask is quite niche so I would not do it just for it. |
Okay, I'll remove the global state for now. Oh, I hit a problem. If we add a |
I don't think thats used really often, most crates have conflicting features anyway (async runtimes for example). |
@Sytten I'd invite you to may be add a more complicated test case to |
#[test]
fn test_more_parentheses_complex() {
// Add pagination
let mut pagination = Cond::all();
let lt_value = Expr::col(Glyph::Aspect)
.lt(1)
.or(Expr::col(Glyph::Aspect).is_null());
let lt_id = Expr::col(Glyph::Aspect)
.is(1)
.and(Expr::col(Glyph::Id).lt(10));
pagination = pagination.add(lt_value.or(lt_id));
// Add filtering
let mut all = Cond::all();
all = all.add(Expr::col(Glyph::Image).eq("png"));
let mut nested = Cond::all();
nested = nested.add(Expr::col(Glyph::Table).gte(5));
nested = nested.add(Expr::col(Glyph::Tokens).lte(3));
all = all.add(nested);
let mut any = Cond::any();
any = any.add(Expr::col(Glyph::Image).like("%.jpg"));
any = any.add(all);
let filtering = any;
// Query
let query = Query::select()
.column(Glyph::Id)
.from(Glyph::Table)
.cond_where(Cond::all())
.cond_where(pagination)
.cond_where(filtering)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
"SELECT `id` FROM `glyph` WHERE ((`aspect` < 1) OR (`aspect` IS NULL) OR ((`aspect` IS 1) AND (`id` < 10))) AND ((`image` LIKE '%.jpg') OR ((`image` = 'png') AND ((`glyph` >= 5) AND (`tokens` <= 3))))"
);
} Done @tyt2y3 |
🎉 Released In 0.30.5 🎉Thank you everyone for the contribution! |
@Sytten
This is what I came up with: feature flag + runtime option. It has a safety mechanism to prevent multiple code paths overriding the same option twice.
Let me know if it works for you