fix: use query.Add for same column filters instead of and operator#84
Open
zugdev wants to merge 1 commit intosupabase-community:mainfrom
Open
fix: use query.Add for same column filters instead of and operator#84zugdev wants to merge 1 commit intosupabase-community:mainfrom
zugdev wants to merge 1 commit intosupabase-community:mainfrom
Conversation
Replace the 25-line appendFilter() implementation that manually constructed PostgREST "and" expressions with a single query.Add() call. PostgREST natively supports duplicate query parameters for the same column and implicitly ANDs them, which is how postgrest-js works (URLSearchParams.append). The previous implementation had bugs: column name prefix collisions, fragile parenthesis string manipulation, and URL encoding issues with the and operator. Update tests to expect duplicate query params (url.Values with slices) instead of a single "and" parameter. Fixes supabase-community#53 Fixes supabase-community#58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix. Resolves #53, #58, supabase-community/supabase-go#13
What is the current behavior?
Chaining multiple filters on the same column (i.e.
.Gte("age", "18").Lte("age", "65")) produces incorrect query parameters. TheappendFilter()function manually constructs a PostgRESTandexpression, which has bugs: column name prefix collisions, fragileTrimSuffix(")")for nested expressions, and percent encoded parentheses fromurl.Values.Encode().This was originally a valid workaround when filters were stored in a
map[string]string, which can only hold one value per key. After the refactor tourl.Values,query.Add()became available but no one updatedappendFilter()to use it.What is the new behavior?
Use
query.Add(column, filterValue)inappendFilter()body. PostgREST natively supports duplicate query parameters for the same column and implicitly ANDs them, this is how postgrest-js works withURLSearchParams.append()for instance.Query output changes from
?and=(age.gte.18,age.lte.65)to?age=gte.18&age=lte.65, but both produce identical SQL at PostgREST.Tests updated to expect
url.Valueswith multiple values per key instead of a singleandparameter.