feat: [#708] facades.DB() Support JSON Where Clauses#1082
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for JSON where clauses in DB queries by allowing the use of the "->" operator and introducing related JSON handling functions. Key changes include:
- New JSON query test cases and table setup in tests/db_test.go.
- Updates to query building functions in the database/gorm and database/db packages to support JSON operators.
- Consistent updates to contracts and driver interfaces to include new JSON where clause operations.
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 |
|---|---|
| tests/go.mod | Updates dependency version for samber/lo library |
| tests/db_test.go | Adds tests for various JSON query clauses and new table creation |
| database/gorm/query.go | Refactors query building to use exported fields and new JSON types |
| database/gorm/conditions.go | Updates conditions struct to reference contractsdriver types |
| database/db/query.go | Extends query interface with new JSON query methods |
| database/db/builder.go | Introduces NameMapper for consistent field-to-column mapping |
| contracts/database/driver/conditions.go | Defines new WhereType constants and updates the Where struct |
| contracts/database/db/db.go | Updates DB Query interface to include JSON where clause operations |
Comments suppressed due to low confidence (3)
tests/db_test.go:1427
- [nitpick] Consider extracting lengthy inline JSON literals into helper constants or separate functions to improve readability and maintainability.
Data: `{\n "string": "first",\n "int": 123,\n "float": 123.456,\n "bool": true,\n "array": ["abc", "def", "ghi"],\n ...`
contracts/database/db/db.go:114
- [nitpick] Consider adding inline documentation comments to the new JSON query interface methods to clarify their purpose and usage for API consumers.
OrWhereJsonContains(column string, value any) Query
database/db/builder.go:30
- [nitpick] Verify that the NameMapper function covers all necessary edge cases for converting struct field names to snake case, especially for fields beyond 'ID'.
dbx.MapperFunc(NameMapper)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1082 +/- ##
==========================================
+ Coverage 71.03% 71.13% +0.10%
==========================================
Files 181 181
Lines 12710 12720 +10
==========================================
+ Hits 9028 9048 +20
+ Misses 3312 3305 -7
+ Partials 370 367 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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: a724b55 | Previous: d5bbc40 | Ratio |
|---|---|---|---|
BenchmarkFile_ReadWrite |
346871 ns/op 6185 B/op 97 allocs/op |
204521 ns/op 6185 B/op 97 allocs/op |
1.70 |
BenchmarkFile_ReadWrite - ns/op |
346871 ns/op |
204521 ns/op |
1.70 |
This comment was automatically generated by workflow using github-action-benchmark.
d2b7ecb to
426e6f3
Compare
|
Hi~ @hwbrzzl ,Is there anything else I need to do for this PR? |
|
So sorry, missed this PR, will check it. |
📑 Description
Closes goravel/goravel#708
Support to query a JSON column, use the
->operator:✅ Checks