Skip to content

QueryBuilder multiply and divide support #3373

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

Merged
merged 6 commits into from
Jun 10, 2025

Conversation

faissaloux
Copy link
Contributor

Hello 👋🏻

In this PR I have added multiply and divide to QueryBuilder .

Usage

DB::table('users')->where('name', 'John Doe')->multiply('salary');    // "salary" * 1
DB::table('users')->where('name', 'John Doe')->multiply('salary', 2); // "salary" * 2
DB::table('users')->where('name', 'John Doe')->divide('salary');      // "salary" / 1
DB::table('users')->where('name', 'John Doe')->divide('salary', 2);   // "salary" / 2

Checklist

  • Add tests and ensure they pass

@faissaloux faissaloux requested a review from a team as a code owner April 26, 2025 21:23
@faissaloux faissaloux requested a review from GromNaN April 26, 2025 21:23
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this nice feature that leverage MongoDB update operator.

Could you tell me a bit more about your use-case?

@faissaloux
Copy link
Contributor Author

Could you tell me a bit more about your use-case?

Case of storing price in cents

We need to get the price converted from cents to USD.

DB::table('products')->where('title', 'socks')->divide('price', 100);

Case of adding tax

DB::table('products')->where('title', 'socks')->multiply('price', 1.2);

@faissaloux faissaloux requested a review from GromNaN April 30, 2025 21:25
@faissaloux faissaloux requested a review from GromNaN May 23, 2025 14:28
@GromNaN GromNaN modified the milestones: 5.4, 5.5 Jun 10, 2025
@GromNaN GromNaN enabled auto-merge (squash) June 10, 2025 07:57
@GromNaN
Copy link
Member

GromNaN commented Jun 10, 2025

Thank you @faissaloux

@GromNaN GromNaN merged commit e2b119a into mongodb:5.x Jun 10, 2025
71 checks passed
@faissaloux faissaloux deleted the querybuilder-multiply-and-divide branch June 10, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants