Skip to content

Added aggregate methods #42

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

Merged
merged 21 commits into from
Jan 20, 2024
Merged

Added aggregate methods #42

merged 21 commits into from
Jan 20, 2024

Conversation

StemateF
Copy link

Hi there,

I added missing aggregate functions.

Unfortunately I will need some help with the tests, I couldn't figure out how the whole test setup actually works 😢.

@alexzarbn Please let me know what you think, if you have suggestions on improving this.

Thanks

dependabot bot and others added 3 commits October 17, 2023 02:59
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.13.13 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [axios](https://github.com/axios/axios) from 0.21.2 to 1.6.0.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v0.21.2...v1.6.0)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
query.withCount()
query.withExists()
query.withSum()
query.withAvg()
query.withMin()
query.withMax()
@alexzarbn
Copy link
Member

Hi @StemateF,

Thank you for the PR!

Overall it looks good, as for the tests - integration tests are built on top of MirageJS, you can take a look at their docs to get yourself familiar with the concept, as well as check out the retrieving a paginated list resources with included relations test in queryBuilder.test.ts and try to implement a similar logic for the newly introduced methods on QueryBuilder.

@StemateF
Copy link
Author

@alexzarbn Done.
I also fixed a typing issue on the new type I created (oops 😅 )
Added some basic testing following the test you referenced.
Let me know if there are more changes required, will be happy to make them.

@alexzarbn
Copy link
Member

alexzarbn commented Jan 7, 2024

Hi @StemateF,

Awesome, looking great overall! One fix is required before I merge this - TS complains about missing information in runtime.

Screenshot 2024-01-07 at 11 23 56

Added types to with(), .withCount(), .withExists()
query.withCount()
query.withExists()
query.withSum()
query.withAvg()
query.withMin()
query.withMax()
Added types to with(), .withCount(), .withExists()
# Conflicts:
#	tests/integration/orion.test.ts
@StemateF
Copy link
Author

StemateF commented Jan 7, 2024

Hi @alexzarbn, I've addressed the TypeScript errors in the code, funny enough I had to update my ts for the errors to come up on my end.

Additionally, I have included types for the .with() method. Please note that this might be a breaking change, as it could disrupt builds when attempting to include a relation that hasn't been defined. Similarly, trying to include a nested relation with a depth greater than 2 (e.g., users.posts.tags) will not work; only users.posts will be valid.

I'm open to increasing the depth to a larger value if needed, but implementing recursion could pose challenges. This is particularly true when two models reference each other, resulting in a scenario where the type becomes something like users.posts.user.posts.user.... Handling this recursive situation may be intricate. Let me know your thoughts on these changes.

@alexzarbn
Copy link
Member

@StemateF Thank you for the quick update!

I would suggest not to introduce breaking changes for now and leave the with method as is and just have the types working for the aggregates.

Also, I'm not sure if using string & keyof Relations construct would actually preserve the type string in the runtime, were you able to confirm it works?

@StemateF
Copy link
Author

@alexzarbn I undid the changes to the with method.

I am not sure I understand what you mean by "runtim" you mean the transpiled version of the sdk? The one in lib?
If so it does work, this is what I get in phpstorm after changing the imports to lib.

image

@StemateF
Copy link
Author

Now that i look at this, I realized that the new methods will suffer from the same issue I highlighted in my previous comment "#42 (comment)".

Might be best to just give up on types for the relations names as it might be limiting for some users.

@alexzarbn
Copy link
Member

@StemateF What I mean is the js output that, when used, might not work correctly, since it does not have the type information.

I will merge it as is, and will see, if any issues pop up.

@alexzarbn alexzarbn merged commit 884dcc1 into tailflow:main Jan 20, 2024
@StemateF
Copy link
Author

@alexzarbn Sounds good, thanks. Is there a planned release for the new version of the sdk on NPM ?

@alexzarbn
Copy link
Member

@alexzarbn Sounds good, thanks. Is there a planned release for the new version of the sdk on NPM ?

Published v4.1.0 just now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants