-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add builders and execute for repository #792
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
Conversation
1382122 to
b586c49
Compare
bajtos
left a comment
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.
Good work, @raymondfeng! I did not review all new tests and builder methods in detail, but I don't see any major problems beyond the things pointed out below.
At high level, please check why our code coverage is decreased by your changes by -0.3%, I think your tests are missing some important use cases.
| * Sorting order for matched entities | ||
| */ | ||
| order?: Order[]; | ||
| order?: string[]; |
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 am worried that this change will allow people to accidentally use invalid values for order and the TypeScript compiler will not catch that problem. Can we preserve this type? Unless I am missing something?
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.
There are a few issues around this signature:
-
Order is defined as
{[field: string]: Direction}. That means we can have{a: 'ASC', b: 'DESC'}. Do we translate it toORDER BY A ASC, B DESC? If so, can we avoidOrder[]`? -
string[]is not very intuitive. I use it internally for now to avoid translation to legacy jugglerorderformat. -
The
FilterBuildertakesOrderfor type safety.
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 see, I think I got confused about the difference between Order and Direction, as it seems to be the same thing. Maybe Ordering would be a better type name?
In the light of your comment, I am ok to keep the current implementation, but please add a comment explaining why we are using string[] type here and perhaps add a link pointing to our docs where people can learn more about valid values.
packages/repository/src/query.ts
Outdated
| } | ||
|
|
||
| /** | ||
| * A builder for Where object |
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.
Please include a short example showing how to use this builder.
packages/repository/src/query.ts
Outdated
| } | ||
|
|
||
| /** | ||
| * A builder for Filter |
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.
Please include a short example showing how to use this builder.
| class AppWithRepoMixin extends RepositoryMixin(Application) {} | ||
|
|
||
| class NoteRepo { | ||
| class NoteRepo implements Repository<any> { |
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 think this should be Repository<Note>, or at least Repository<Entity>. Thoughts?
b586c49 to
23a8ac7
Compare
40abe76 to
796ff03
Compare
bajtos
left a comment
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 cannot tell what you changed in the tests (because there is only a single commit), but since the code coverage is going up now, I am happy 😄
I found few minor things to improve before this is landed, see below.
Other than that, the patch LGTM.
packages/repository/src/query.ts
Outdated
| * `and`, `or`, and other operators. | ||
| * | ||
| * @example | ||
| * ``` |
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.
Please add ts or js after the last back-tick to enable syntax highlighting.
packages/repository/src/query.ts
Outdated
| * @example | ||
| * ``` | ||
| * const whereBuilder = new WhereBuilder(); | ||
| * const where = whereBuilder |
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.
Please keep the indentation consistent.
packages/repository/src/query.ts
Outdated
| * `fields`, `order`, `where`, `limit`, `offset`, and `include`. | ||
| * | ||
| * @example | ||
| * ``` |
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.
Please add ts or js after the last back-tick to enable syntax highlighting.
796ff03 to
be5aec4
Compare
Add builders with fleunt APIs to build Filter and Where objects Add execute method to Repository interfaces
be5aec4 to
842dea8
Compare
Description
The PR adds
execute()andbuildersfor ourFilter/Whereobjects.Related issues
Checklist