fix: Complete schema-based JSON detection and remove hardcoded field lists (#61, #59) #62
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
This PR completes the migration to schema-based JSON/JSONB field detection by removing all hardcoded field name lists. This work builds on #60 and fully resolves issues #61, #59, and #20.
Changes
Schema Enhancement (Issue #61)
pg.FieldSchemawithIsJSONBandElementTypefieldsLoadTableSchema()to populate these fields from PostgreSQL database schemaisFieldJSONB(tableName, fieldName)- detect JSONB vs JSON typeisFieldArray(tableName, fieldName)- detect array columnsgetFieldElementType(tableName, fieldName)- get array element typeRemoved Hardcoded Field Lists (Issue #61)
Removed all hardcoded field name lists from detection functions in
json.go:shouldUseJSONPath()- removedjsonFieldslisthasJSONFieldInChain()- now uses schema-based detectionisJSONArrayField()- removedjsonArrayFieldsandarrayFieldNamesmapsisJSONBField()- removedjsonbFieldsandjsonbParentFieldslistsgetJSONArrayFunction()- removedsimpleArrayFieldsandcomplexArrayFieldslistsAPI Refactoring - Functional Options Pattern
Refactored the API to use functional options for better extensibility:
ConvertOptiontype andWithSchemas()option functionConvert()now accepts variadic options instead of separateConvertWithSchemas()functionTest Updates
Convert(ast, cel2sql.WithSchemas(schemas))(PostgreSQL's
information_schemadoesn't provide information about JSON internals)Breaking Change
Users must now provide schema information via the
WithSchemas()option for JSON field detection to work. TheConvert()function without schemas will only work for non-JSON fields.Before:
After:
Test Plan
Related Issues
Closes #61
Closes #59
Closes #20
🤖 Generated with Claude Code