-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add a whereIf
method to query builder
#17
Comments
This might be better instead, as most cases will benefit from this. // better name?
Model.query().whereIgnoreNull('search', args.search)
// or
Model.query().where('search', args.search, {ignoreNull: true}); Above method might create bugs that are harder to spot, eg. // might create an undefined error
Model.query().whereIf(ctx.country, 'id', ctx.country.id); or might be harder to read // harder to see what the condition is
Model.query().whereIf(args.subCategoryId && args.subCategoryId.length, 'Product.subCategoryId', args.subCategoryId) |
These will only be helpful if the condition is the value being compared. What about if the condition is different?
Same goes for // might create an undefined error
Model.query().where('id', ctx.country.id, {ignoreNull: true}); |
Something like Model.query().where((q) => {
q.where('id', options.id).orWhere('id', '<', options.val)
}); Maybe we can implement both, a general purpose Model.query().whereIf(condition, 'id', options.id);
Model.query().whereIf(condition2, 'id', '<', options.val);
Model.query().whereIf(condition3, (q) => {
q.where('id', options.id).orWhere('id', '<', options.val)
}); And a |
The simple cases can already be handled in objection through |
Something like:
The text was updated successfully, but these errors were encountered: