-
Notifications
You must be signed in to change notification settings - Fork 181
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
array_type_field_filter: Add new contains filter to search on Array type field #460
Conversation
5a5d62f
to
7566064
Compare
c3f9a69
to
1fcf79a
Compare
test/postgresql.test.js
Outdated
@@ -263,6 +263,18 @@ describe('postgresql connector', function() { | |||
}); | |||
}); | |||
|
|||
it('should support where filter for array type field', function(done) { | |||
Post.dataSource.settings.allowExtendedOperators = true; |
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.
After adding this we do not need juggler related PR.
PFB PR Link:
loopbackio/loopback-datasource-juggler#1865
1fcf79a
to
17f56b7
Compare
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.
I like how it's possible to implement your desired feature inside the connector only 👍
I have few comments on implementation details, PTAL above.
Please add a new section to README to explain what extended operators are supported (e.g. @>
) and what is needed to allow the app to use them (set allowExtendedOperators
in model and/or datasource settings).
test/postgresql.test.js
Outdated
categories: {'@>': ['AA']}, | ||
}, | ||
]}}, function(err, post) { | ||
should.not.exist(err); |
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.
should.not.exist(err); | |
if (err) return done(err); |
That way the original error details and the stack trace is preserved.
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.
How we would be handling this with async await type test case? @bajtos
I was thinking to write test case this way for handling failure of testcase with proper details.
it('should support where filter for array type field', async () => {
Post.dataSource.settings.allowExtendedOperators = true;
try {
const post = await Post.find({where: {
categories: {'contains': ['AA']},
}});
should.exist(post);
post.length.should.equal(1);
} catch (err) {
should.not.exist(err);
}
});
Please tell me if it is correct, I will update current test case in this way only.
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.
As a rule of thumb, the tests should pass any unexpected error to the test runner:
- Use
done(err)
when using callback - Use regular error propagation when using async functions
it('should support where filter for array type field', async () => {
Post.dataSource.settings.allowExtendedOperators = true;
const post = await Post.find({where: {
categories: {'contains': ['AA']},
}});
should.exist(post);
post.length.should.equal(1);
});
17f56b7
to
ecf676c
Compare
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.
The new version looks pretty good.
-
Please change the commit message to use the new operator name
-
Please add a new section to README to explain what extended operators are supported (e.g.
@>
) and what is needed to allow the app to use them (setallowExtendedOperators
in model and/or datasource settings). Put yourself in the shoes of other LoopBack users - where would you look for information aboutcontains
operator and what info would you want to see to help you understand how to use this feature in your app?
ecf676c
to
5fc5d1e
Compare
@bajtos Thanks for review.. For Point#1 I have done the update.
|
That's a good question. I believe the postgres connector so far supports only built-in LoopBack operators supported by all (or most?) connectors, so there was no need to explicitly list extended operators. Now that you are implementing the first extended operator, I think you should simply add a new section. You can draw inspiration from MongoDB connector README:
In the case of PostgreSQL and your new |
@bajtos Added the readme section for the new contains operator, Can you review it... |
Implement support for an extended operator `contains` that can be used to filter records that have an array property containing the selected items. Signed-off-by: shubhisood <shubhi.sood@sourcefuse.com>
d8be8fc
to
55c1003
Compare
Thank you @shubhisood for the update. I pushed few more commits to fix the failing builds and improve README content. Let's wait for CI results before landing. |
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
Array properties are represented as juggler `List` instance, we need to modify test assertions to convert them via `toArray()` before applying `.should.eql` check. Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
55c1003
to
8f2da81
Compare
@slnode test please |
@slnode test please |
Landed, thank you @shubhisood for the contribution ❤️ |
Thanks for merging @bajtos |
Include references to all related GitHub issues and other pull requests, for example:
Fixes #342
Checklist
npm test
passes on your machine