feat: add Query Builder date helpers#10266
Conversation
patel-vansh
left a comment
There was a problem hiding this comment.
Overall, this feature can be handy. Looks good. Thanks
|
👋 Hi, @memleakd! |
f96f54d to
e2e6106
Compare
- Add whereDate(), whereYear(), whereMonth(), and whereDay() - Add OR variants for date-part WHERE clauses - Compile date-part expressions per database driver - Document supported operators, null handling, escaping, and index caveats - Add builder and live database coverage Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
445e6d6 to
77371cc
Compare
michalsn
left a comment
There was a problem hiding this comment.
I was thinking about this for some time, and I'm not convinced the new whereDate() method should be added.
If users pass 2026-06-21 12:34:56, we either have to strip the time part silently or accept cross-driver differences. On top of that, the generated SQL wraps the column in date functions/casts like DATE(), CAST(... AS DATE), or EXTRACT(), which prevents use of a normal index on the datetime column.
Of course, we can document these limitations, but for real datetime columns, an explicit range condition is often clearer and more performant. And with whereBetween(), this is now easier to apply than before.
I think this method may be tempting to use in cases where it has the biggest drawbacks.
|
Thanks, I think you’re right. I don’t want to add something that looks convenient but may lead people toward the wrong query shape. I’m fine with closing this PR. Or, if you think it would still be useful, I can turn it into a small docs update showing the safer range-based approach. |
|
In theory, we could implement
My concern is that this adds quite a bit of complexity to an already bloated Builder class. The implementation would need careful operator handling: |
Description
This proposes adding a small set of Query Builder helpers for filtering by parts of a date/datetime column:
The matching OR variants are included as well:
orWhereDate(),orWhereYear(),orWhereMonth(), andorWhereDay().The main goal is to make a common query easier to write without asking users to remember the right SQL function for each database driver. The builder compiles the expression for the active driver, while still binding values and protecting identifiers by default.
A few details are documented explicitly:
whereDate('created_at >=', '2026-01-01')nullvalues useIS NULL/IS NOT NULLTests cover the shared builder behavior, driver-specific SQL output, invalid inputs,
DateTimeInterfacevalues, grouped/or conditions, aliases beforefrom(), and a live database query.Checklist: