Add WithLower, disable exact fallback for WithILikeOps#52
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends pgcql string-field query generation to support optional lower(...) wrapping for case-insensitive matching, and changes WithILikeOps() behavior to always use ILIKE (i.e., no exact-match fallback).
Changes:
- Add
WithLower()support toFieldString, applyinglower()to both column and parameter for non-ILIKEcomparisons (includingIN). - Add
WithoutExact()and updateWithILikeOps()to disable exact-match fallback. - Expand parsing tests to cover the new behaviors (
WithoutExact,WithLower, andWithILikeOpsfallback changes).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
pgcql/pg_field_string.go |
Adds enableLower, WithLower(), WithoutExact(), and adjusts LIKE/ILIKE vs exact fallback logic. |
pgcql/pgcql_test.go |
Adds test coverage for like-only fields, lower-wrapped comparisons, and updated ILIKE behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -324,9 +350,15 @@ func (f *FieldString) Generate(sc cql.SearchClause, queryArgumentIndex int) (str | |||
| pgOp = "NOT ILIKE" | |||
| } | |||
| } | |||
| return f.column + " " + pgOp + fmt.Sprintf(" $%d", queryArgumentIndex), []any{pgTerm}, nil | |||
| if f.enableILike { | |||
| return f.column + " " + pgOp + fmt.Sprintf(" $%d", queryArgumentIndex), []any{pgTerm}, nil | |||
| } | |||
| return f.getQueryColumn() + " " + pgOp + " " + f.getQueryArg(queryArgumentIndex), []any{pgTerm}, nil | |||
| } | |||
| } | |||
| if !f.enableExact { | |||
| return "", nil, &PgError{message: "unsupported relation " + string(sc.Relation)} | |||
There was a problem hiding this comment.
WithILikeOps() now sets enableExact=false, but the LIKE/ILIKE branch only triggers for relations =, <>, and exact (not ==). As a result, queries like authori==Test (or any field configured with WithoutExact()) will now fall through and return unsupported relation ==, which is inconsistent with other field types and with existing support for == as equality. Consider treating == the same as = in the LIKE/ILIKE handling (and/or mapping it before the enableExact check), and add a regression test for == on ILIKE/like-only fields.
| {"authori = \"test*\"", "Author ILIKE $1", []any{"test%"}}, | ||
| {"authori <> \"test*\"", "Author NOT ILIKE $1", []any{"test%"}}, | ||
| {"authori = Test", "Author ILIKE $1", []any{"Test"}}, | ||
| {"authori <> Test", "Author NOT ILIKE $1", []any{"Test"}}, | ||
| {"authoriLower = \"test*\"", "Author ILIKE $1", []any{"test%"}}, | ||
| {"authoriLower <> \"test*\"", "Author NOT ILIKE $1", []any{"test%"}}, | ||
| {"authoriLower = Test", "Author ILIKE $1", []any{"Test"}}, | ||
| {"titleLower = AbC", "lower(Title) = lower($1)", []any{"AbC"}}, |
There was a problem hiding this comment.
The new behaviors around WithILikeOps() (no exact fallback) and WithoutExact() aren’t exercised with the == relation, which is used elsewhere in this test suite (e.g., title==2). Adding a couple of authori==... / authorLikeOnly==... cases here would catch regressions where == is accidentally rejected or handled differently than =.
No description provided.