-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(DataStore): QueryPredicate translation #961
Conversation
Codecov Report
@@ Coverage Diff @@
## main #961 +/- ##
==========================================
+ Coverage 70.39% 70.50% +0.10%
==========================================
Files 920 920
Lines 39049 39194 +145
==========================================
+ Hits 27490 27632 +142
- Misses 11559 11562 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
let indentPrefix = " " | ||
var indentSize = 1 | ||
var groupOpened = false | ||
|
||
func translate(_ pred: QueryPredicate) { | ||
func translate(_ pred: QueryPredicate, opAhead: Bool, groupType: QueryPredicateGroupType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
opAhead
: decide whetherand
oror
operator should be added before bracket depends on -
groupType
: the operation applied to twoQueryPredicateOperation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you have to explain the variable name here then consider renaming the variable and refactor as you try to rename it. If the variable still needs some explanation, then better add some documentation to the top of the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the android implementation, it looks pretty elegant:
https://github.com/aws-amplify/amplify-android/blob/fef0cc31b50c427c60e144346a896c20a2f440e4/aws-datastore/src/main/java/com/amplifyframework/datastore/storage/sqlite/adapter/SQLPredicate.java#L108
Maybe we can get some inspiration from their codebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any tests at the unit test or integration test level that would run against a real SQL store to ensure the issue is fixed ?
@@ -57,7 +64,7 @@ private func translateQueryPredicate(from modelSchema: ModelSchema, | |||
} | |||
} | |||
} | |||
translate(predicate) | |||
translate(predicate, predicateIndex: -1, groupType: .and) // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could also have default parameter values as -1 and .and
for the translate
method and comment on top why the default values are used. or add the comment on top here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added some descriptive words
class DataStoreLocalStoreTests: LocalStoreIntegrationTestBase { | ||
|
||
/// - Given: 4 posts that has been saved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added one integration test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Issue #, if available:
A fix for issue: #907
Description of changes:
The previous translation from
QueryPredicate
to sql statement is incorrectFor example:
If I have a predicate like
SQL statement generated by the incorrect code is:
which fails
DataStore.query()
The correct one should be:
My PR update the implementation of ConditionStatement generation
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.