Add a new field to indicate whether to perform a length comparison #291
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 did this pull request do?
This PR adds a length function to the JSONArrayQuery feature, enabling the comparison of the length of JSON array fields. Specifically, it adds length - related fields to the JSONArrayExpression struct, a new Length method for setting comparison conditions, and implements the construction logic of length comparison SQL statements for MySQL, SQLite, and PostgreSQL databases in the Build method. This resolves the issue that the original code could not verify the equality of JSON array lengths
User Case Description
In the business scenario, data query and creation operations are required based on conditions involving JSON array - type fields. For example, in the DoGetOrCreateStrategyKey interface, data is queried and created according to the incoming StrategyIds array. The original JSONArrayQuery only supports verifying the containment of array elements and cannot verify whether the array lengths are the same. The newly added length function ensures that during querying, existing data is only returned when both the length and content of the JSON array match. When the lengths are the same but the contents are different, it is treated as new data for creation, meeting more precise business query requirements.
Specific example scenario
You can only verify that it belongs to, not that it is equal to, for example, this interface:
Two requests are passed in separately:
The second request was supposed to create a new piece of data, but it returned the data created by the first request.
After adding the length attribute, you can compare with one click, which is more convenient