Case-sensitive contains, starts_with and ends_with that match % and _ literally on every database
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
Research direction
Start with crates/database/src/db/builder/expr.rs around Expr::like_text and crates/database/src/db/builder/compile.rs around glob_pattern and SQLite like_case_sensitive compilation. Trace how the existing literal matchers escape text and how case-sensitive patterns compile for each database, then add equivalent coverage for the proposed Expr and text model column methods. Done means %, _ and backslash match literally with case respected across the supported engines.
Written by the indexing model from the issue text.
Description
The problem
starts_with, ends_with and contains match text literally (%, _ and \ in the text match only themselves), but they always ignore case where the engine does. like_case_sensitive tells case apart on every engine, but it takes a pattern, and there's no portable way to put a literal % or _ in that pattern:
- On PostgreSQL, MySQL and MariaDB,
\%is a literal%, because\islike's default escape there. - On SQLite,
like_case_sensitivebecomes aglobwithEscape::Driver(compile.rsL556, L1524–L1545).%always becomes*and_becomes?, and a\is a literal backslash. Solike_case_sensitive("100\\%%")finds "100% off" on PostgreSQL and MySQL, and any text that starts with100\on SQLite.
The escaping that contains does is Expr::like_text, which is pub(crate) (expr.rs L874–L891). glob_pattern already handles Escape::Backslash, so a case-sensitive like_text would compile correctly on SQLite; nothing public builds one.
Laravel
Laravel Classic's whereLike($column, $value, caseSensitive: true) has the same gap on SQLite: SQLiteGrammar::whereLike turns the pattern into a glob by replacing % and _, so it can't hold them literally either. Laravel has no contains helper, so it has nothing to escape.
Proposal
Case-sensitive versions of the literal matchers, on Expr and on text model columns:
db::table("coupons").filter(col("code").contains_case_sensitive("50%"));
Coupon::query().filter(Coupon::code.starts_with_case_sensitive("VIP_"));
They escape text as contains does and compile as like_case_sensitive does, with Escape::Backslash, so SQLite's glob keeps % and _ as literal characters and every engine matches the same rows. Alternatively, like_text could become public with a Case argument, but three named methods follow the existing like / like_case_sensitive pair.
Use case
An exact-match search box in a package's data table, or an operations dashboard that filters log lines or SKUs where case matters and the text can hold % or _ (50%_OFF, api_v2). Today that needs like_case_sensitive with hand-escaped input that's only correct off SQLite, or raw instr(column, ?) with a separate branch per engine.
- Dominant language
- Rust
- Stars
- 847
- Forks
- 174
- Avg merge
- 5h 40m
- Merged PRs (30d)
- 167
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from laravel/rust-framework
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
laravel/rust-framework#864 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
laravel/rust-framework#876 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
laravel/rust-framework#873 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#872 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
laravel/rust-framework#871 ·
Maintainers usually reply within 1 day
All issues in laravel/rust-framework
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neuralmagic/crucible#579 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
eclipse-score/kyron#249 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
seanmonstar/reqwest#3157 ·
Maintainers usually reply within 2 days