Add JSONB-key range filters#82
Draft
HodaSalim wants to merge 1 commit into
Draft
Conversation
Lets a range (a...b) target a key inside a :jsonb column, with the cast type declared per key via a new keys: option on filter_on (accepting a Hash or a per-request callable). Resolves the latent bug where a "..." inside a jsonb value was mis-parsed as a whole-string Range, producing broken SQL. Supported range key types: :int, :decimal, :date, :datetime, :time. A range on an undeclared/unsupported key type now yields a clear validation error instead of broken SQL. Closes #80. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Implements #80. Lets a range (
a...b) target a key inside a:jsonbcolumn, with the cast type declared per key. Also resolves a latent bug where a...inside a jsonb value was mis-parsed as a whole-stringRange, producing broken SQL.keys:option onfilter_onfor:jsonbfilters, declaring the cast type per key. Accepts either a Hash ({ price: :decimal }) or a callable (->(key) { ... }) resolved per request (covers dynamic keys like custom-field definition IDs).?filters[metadata]={"price":"10...100"}→(metadata->>'price')::numeric BETWEEN 10 AND 100(inclusive; bounds are bind params, key is escaped).:int,:decimal,:date,:datetime,:time(casts:::integer,::numeric,::date,::timestamptz,::time)....are no longer treated as aRange.Existing JSONB behavior (array containment, key equality, null handling) is unchanged.
Key changes
filter_on/Filter/Parameter: threadkeys:; addParameter#key_typeand#range_key?.ValueParser: per-key range parsing; guard whole-string range detection for jsonb objects.WhereHandler:apply_jsonb_rangebranch with type-driven cast.TypeValidator+ newValidJsonbValidator: declared-key-type and bounds validation.docs/filters.md),CHANGELOG.md, version bump1.0.1→1.1.0.Test plan
bundle exec rake test— 124 runs, 220 assertions, 0 failures, 0 errorsRangefor declared keys; non-range/whole-string jsonb unchanged (value_parser_test)(...)::<cast> BETWEEN ? AND ?with bound params for each key type (where_handler_test)key_typeresolves from Hash and callable (parameter_test)filter_validator_test)controller_test)Made with Cursor