-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add support for ordering on $select clauses in aggregations #393
Conversation
Change the Exclude in the part to use keyof
- Replace AggregatableKeys | with ValidAggregationKeys
This was done by wrapping the `AggregateOptionsThatErrors` in another `AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy` type. This also inadvertently fixed the broken aggregate.test.ts file. This makes no sense. Adding another layer somehow helped TypeScript correctly infer the original type again?
packages/client/src/query/aggregations/AggregationResultsWithoutGroups.ts
Outdated
Show resolved
Hide resolved
import type { GroupByClause } from "../query/aggregations/GroupByClause.js"; | ||
|
||
export type AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy< |
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 tried a few different approaches for enforcing the "can't order on $select if there are multiple $groupBy clauses" restriction in the type system, and this method of adding another wrapped type layer around the AggregateOptsThatErrors
type just to check this restriction was the easiest way to do it.
@ericanderson was this an okay approach?
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 need to check out the repo to play with the types/intellisense but this seems like a reasonable solution.
The issue the comment was describing was fixed in f1ca1e1.
packages/client/src/internal/conversions/legacyToModernSingleAggregationResult.ts
Outdated
Show resolved
Hide resolved
da281f5
to
d7b7762
Compare
This reverts commit 519fd7b.
…h as I can Leaving as is - it doesn't seem any worse than before this PR.
return [ | ||
{ | ||
type: metric as StringAggregateOption | NumericAggregateOption, | ||
name: `${property}.${metric}`, |
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.
Worth checking, could probably just reuse k
/propAndMetric
here. The existing name was just an arbitrary choice by me that I knew we could split on later.
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 the property.metric string is what gets sent to the wire as part of the request body, so the reformatting from property:metric to property.metric is necessary
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.
It is whats in the request body, but the backend doesn't care what this value is. It will simply return a result that matches that value.
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.
We can leave as is for now
packages/client/src/internal/conversions/modernToLegacyAggregationClause.ts
Outdated
Show resolved
Hide resolved
packages/client/src/internal/conversions/modernToLegacyAggregationClause.ts
Outdated
Show resolved
Hide resolved
import type { GroupByClause } from "../query/aggregations/GroupByClause.js"; | ||
|
||
export type AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy< |
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 need to check out the repo to play with the types/intellisense but this seems like a reasonable solution.
packages/client/src/query/aggregations/AggregationResultsWithoutGroups.ts
Outdated
Show resolved
Hide resolved
packages/client/src/query/aggregations/AggregationResultsWithoutGroups.ts
Outdated
Show resolved
Hide resolved
packages/client/src/query/aggregations/AggregationResultsWithoutGroups.ts
Outdated
Show resolved
Hide resolved
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 have my blessing if you have Saurav's blessing
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.
Approved, couple of unblocking comments
Opening draft PR while I start writing tests