Skip to content

feat: add Query Builder whereBetween methods#10199

Open
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/query-builder-where-between
Open

feat: add Query Builder whereBetween methods#10199
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/query-builder-where-between

Conversation

@memleakd
Copy link
Copy Markdown
Contributor

Description

This PR proposes adding whereBetween(), orWhereBetween(), whereNotBetween(), and orWhereNotBetween() to the Query Builder.

BETWEEN and NOT BETWEEN conditions are common when filtering by date ranges, numeric ranges, prices, scores, and other lower/upper bound values. Today users can already write these conditions manually with where(), but that usually means writing the BETWEEN ... AND ... expression as a raw condition.

This adds a small Query Builder-native option:

$builder->whereBetween('created_at', ['2026-01-01', '2026-01-31']);

This keeps range conditions readable while still using Query Builder binds for the lower and upper values and normal identifier protection for the field name.

The range array must contain exactly two values: the lower and upper bounds. BETWEEN is inclusive, matching SQL behavior.

The API follows the existing Query Builder style used by methods like whereIn(): field name first, values second, optional $escape third. Users who need a more complex SQL expression can still use where() with RawSql.

Changes

  • Added whereBetween() and orWhereBetween().
  • Added whereNotBetween() and orWhereNotBetween().
  • Added Model PHPDoc forwarding entries.
  • Added user guide docs, class reference entries, and changelog entry.
  • Added tests for normal, OR, NOT BETWEEN, grouped conditions, bind handling, escape: false, table prefixes, aliases added after the condition, and invalid inputs.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Add whereBetween(), orWhereBetween(), whereNotBetween(), and
orWhereNotBetween() to Query Builder.

- Bind lower and upper range values through the existing bind system
- Protect identifiers at compile time for alias and prefix correctness
- Add Model method annotations, user guide docs, and changelog entry
- Cover normal, OR, NOT, grouped, unescaped, aliased, prefixed, and invalid input cases

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label May 13, 2026
@memleakd memleakd changed the title feat(database): add query builder between conditions feat: add Query Builder whereBetween methods May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant