feat: [#705] facades.Orm().Query() support JSON where clauses#1074
feat: [#705] facades.Orm().Query() support JSON where clauses#1074
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: aae38ba | Previous: b2b1821 | Ratio |
|---|---|---|---|
BenchmarkFile_ReadWrite |
360958 ns/op 6186 B/op 97 allocs/op |
217821 ns/op 6185 B/op 97 allocs/op |
1.66 |
BenchmarkFile_ReadWrite - ns/op |
360958 ns/op |
217821 ns/op |
1.66 |
This comment was automatically generated by workflow using github-action-benchmark.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1074 +/- ##
==========================================
+ Coverage 70.87% 71.03% +0.15%
==========================================
Files 180 181 +1
Lines 12644 12710 +66
==========================================
+ Hits 8962 9028 +66
Misses 3312 3312
Partials 370 370 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for JSON-based WHERE clauses in the ORM, enabling -> operators and JSON-specific query methods.
- Introduces new
WhereJson*/OrWhereJson*methods and integrates them intoQuery.buildWhere. - Extends the
Wraputility with JSON path parsing (JsonFieldAndPath,JsonPath,JsonPathAttributes) and value wrapping customization. - Updates driver contracts/mocks to include a new
JsonGrammarinterface, adds a new error type, and augments test coverage inwrap_test.go.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| database/gorm/query.go | Added JSON where support and placeholder builder; factored addWhere. |
| database/schema/wrap.go | Implemented JSON path parsing and configurable value wrapper. |
| database/schema/wrap_test.go | Added tests for JSON field/path handling and value-wrapper toggles. |
| errors/list.go | Declared a new error for invalid JSON bindings. |
| contracts/database/driver/grammar.go | Extended Grammar contract with JsonGrammar. |
| mocks/database/driver/JsonGrammar.go & Grammar.go | Generated mocks for the new JSON grammar methods. |
Comments suppressed due to low confidence (6)
database/gorm/query.go:943
- Consider adding unit tests for the new
WhereJson*andOrWhereJson*methods to validate that SQL is generated as expected for various JSON path scenarios.
func (r *Query) WhereJsonContains(column string, value any) contractsorm.Query {
database/gorm/query.go:1377
- The
reflect.ValueOfcall requires importing thereflectpackage; addimport "reflect"at the top of this file.
if val := reflect.ValueOf(args[0]); val.Kind() == reflect.Slice || val.Kind() == reflect.Array {
database/schema/wrap.go:95
- Default quoting in
JsonPathAttributesusesr.Quote(double quotes), but the tests expect single-quoted values ('column'). Adjust the default to wrap with single quotes or update the tests to match double-quote behavior.
return r.Quote(v)
database/schema/wrap_test.go:68
- Typo in helper name:
spiltPathshould besplitPath. Also remove the emptyifblock inside this function.
spiltPath := func(v string) []string {
database/schema/wrap.go:63
- [nitpick] Regexps are being compiled on every call. Consider precompiling these patterns to package-level
varso they aren’t recompiled repeatedly.
value = regexp.MustCompile(`(\\+)?'`).ReplaceAllString(value, "''")
contracts/database/driver/grammar.go:166
- You’ve extended the
Grammarcontract withJsonGrammar, but the default driver grammar implementations (e.g., MySQL, Postgres) must also implement these new methods (CompileJsonContains,CompileJsonContainsKey, etc.). Add their implementations or tests will fail to compile.
type JsonGrammar interface {
|
Thanks, checking... |
hwbrzzl
left a comment
There was a problem hiding this comment.
Amazing PR 👍 Only left one question
|
I will submit a separate PR to fix and add the external tests after the database driver repository PR is merged. |
📑 Description
Closes goravel/goravel#705
Support to query a JSON column, use the
->operator:✅ Checks