Skip to content
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

feat: add orderByRaw to loadManyByRawWhereClauseAsync #185

Merged

Conversation

FiberJW
Copy link
Contributor

@FiberJW FiberJW commented Aug 1, 2022

Why

To achieve the sort I want for Expo apps (ORDER BY GREATEST(display_name, SPLIT_PART(full_name, '/', 2)) ASC), Entity needs a raw order clause option.

How

I added an orderByRaw property to the querySelectionModifiers for loadManyByRawWhereClauseAsync and updated all of the downstream types and call sites accordingly.

Test Plan

The added integration test and Typescript checks should pass.

@linear
Copy link

linear bot commented Aug 1, 2022

@codecov
Copy link

codecov bot commented Aug 1, 2022

Codecov Report

Merging #185 (d5bd112) into main (af81981) will increase coverage by 0.01%.
The diff coverage is 92.85%.

@@            Coverage Diff             @@
##             main     #185      +/-   ##
==========================================
+ Coverage   96.27%   96.29%   +0.01%     
==========================================
  Files          80       80              
  Lines        2015     2023       +8     
  Branches      244      245       +1     
==========================================
+ Hits         1940     1948       +8     
  Misses         75       75              
Flag Coverage Δ
integration 96.29% <92.85%> (+0.01%) ⬆️
unittest 96.29% <92.85%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/entity/src/EntityLoader.ts 89.36% <0.00%> (ø)
...-adapter-knex/src/PostgresEntityDatabaseAdapter.ts 100.00% <100.00%> (ø)
packages/entity/src/EnforcingEntityLoader.ts 100.00% <100.00%> (ø)
packages/entity/src/EntityDatabaseAdapter.ts 100.00% <100.00%> (ø)
packages/entity/src/internal/EntityDataManager.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@FiberJW FiberJW marked this pull request as ready for review August 1, 2022 19:31
@FiberJW FiberJW requested a review from wschurman as a code owner August 1, 2022 19:31
Copy link
Member

@wschurman wschurman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a few things to add:

  • In StubDatabaseAdapter, we should throw an exception in fetchManyByFieldEqualityConjunctionInternalAsync if orderByRaw is specified. Same change should be applied to InMemoryDatabaseAdapter.

One larger question: Do you think this makes more sense to limit this arg to loadManyByRawWhereClauseAsync? Having it present in loadManyByFieldEqualityConjunctionAsync creates a situation where we can't simulate a query in memory (see note above about adding the throws) where up until now we could. My gut says that so far we've used loadManyByRawWhereClauseAsync as the escape hatch for needing to do special SQL things in the database adapters, so it might make more sense for this to just be available in that method (especially because we can't simulate it in the in-memory database adapters mentioned above). That being said, I think your particular use case used loadManyByFieldEqualityConjunctionAsync so maybe not?

@FiberJW
Copy link
Contributor Author

FiberJW commented Aug 3, 2022

I think it makes sense to limit this arg to loadManyByRawWhereClauseAsync.

Which of the following do you think is the better approach:

  • error out in loadManyByFieldEqualityConjunctionAsync when orderByRaw is provided in querySelectionModifiers
  • add a new orderByRaw param to loadManyByRawWhereClauseAsync after querySelectionModifiers
  • extend the querySelectionModifiers type like this PR does, but only in the loadManyByRawWhereClauseAsync codepath (QuerySelectionModifiers<TFields> & { orderByRaw?: string })

@wschurman
Copy link
Member

  • extend the querySelectionModifiers type like this PR does, but only in the loadManyByRawWhereClauseAsync codepath (QuerySelectionModifiers<TFields> & { orderByRaw?: string })

I like this option.

@FiberJW FiberJW changed the title feat: add orderByRaw to querySelectionModifiers feat: add orderByRaw to loadManyByRawWhereClauseAsync Aug 4, 2022
@FiberJW FiberJW requested a review from wschurman August 4, 2022 19:23
Copy link
Member

@wschurman wschurman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a lot better. Probably worth create a new set of types that extends the query modifiers type that includes the new param. This way the internal and external types of the library match and are named. I tried it in 3d2d189 (commit on top of yours) to be sure and it seemed to work (feel free to use all or none of that commit).

@FiberJW FiberJW requested a review from wschurman August 9, 2022 02:11
@wschurman
Copy link
Member

(don't worry about diff target codecov percentage)

@wschurman
Copy link
Member

Ping me when you land this and I'll create a new release of these and upgrade them in www.

@FiberJW FiberJW merged commit 2817d78 into main Aug 9, 2022
@FiberJW FiberJW deleted the fiberjw/eng-5915-add-orderbyraw-option-to-entity-query branch August 9, 2022 17:44
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