-
Notifications
You must be signed in to change notification settings - Fork 201
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
Refactor pagination SQL queries to use generic paramaters #2021
Conversation
Will the empty list not generate a type error? |
No, using the
It will get rid of that error but you may need to annotate it with the type of
to fix that, you can: (users, pagination) <- paginatedSqlQuery @User "SELECT * FROM users" [] Should I add this as well? |
Yes, I think it's best to have a fully working example. |
Changes examples to use [] to match the expected [Action] parameter type.
282a457
to
dbd7bb5
Compare
The type of Line 416 in 17f17b5
|
41fad11
to
08fc538
Compare
@rvarun11 We played with this exact problem recently and ran into lots of weird stuff with the constraints. I believe the I think it seems to be needed here because of the subquery to do the count query. We actually implemented this exact function in our project a few months ago and were able to avoid the need for |
Update: sorry, I got confused. And |
5733289
to
4359aac
Compare
@mpscholten It is ready for review |
@@ -179,12 +173,12 @@ defaultPaginationOptions = | |||
-- | |||
-- *AutoRefresh:* When using 'paginatedSqlQuery' with AutoRefresh, you need to use 'trackTableRead' to let AutoRefresh know that you have accessed a certain table. Otherwise AutoRefresh will not watch table of your custom sql query. | |||
paginatedSqlQuery | |||
:: forall model | |||
. ( FromRow model | |||
:: ( FromRow r |
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.
Why was the type variable name changed from model
to r
?
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.
To maintain consistency with similar functions:
Line 379 in 17f17b5
sqlQuery :: (?modelContext :: ModelContext, PG.ToRow q, PG.FromRow r) => Query -> q -> IO [r] |
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.
Makes sense, but let's keep the old name. Single variable names are not good. (We should eventually patch sqlQuery
to fix this there as well)
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. That makes sense. I've updated the PR accordingly.
@@ -202,14 +196,14 @@ paginatedSqlQuery = paginatedSqlQueryWithOptions defaultPaginationOptions | |||
-- | |||
-- *AutoRefresh:* When using 'paginatedSqlQuery' with AutoRefresh, you need to use 'trackTableRead' to let AutoRefresh know that you have accessed a certain table. Otherwise AutoRefresh will not watch table of your custom sql query. | |||
paginatedSqlQueryWithOptions | |||
:: forall model | |||
. ( FromRow model | |||
:: ( FromRow r |
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.
same here
4359aac
to
efeca2b
Compare
Change type signatures to use generic `parameters` type with `ToRow` constraint instead of `[Action]`
efeca2b
to
2cd71cf
Compare
Changes examples to use [] to match the expected [Action] parameter type.