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

How to do filtering + pagination? #596

Open
jnfeinstein opened this issue May 11, 2021 · 1 comment
Open

How to do filtering + pagination? #596

jnfeinstein opened this issue May 11, 2021 · 1 comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@jnfeinstein
Copy link

Please let me know if there is a better place to address usage questions.

I am trying to take an application beyond basic boilerplate by adding both multi-tenancy and pagination/sorting. Tenancy is achieved using a many-to-one relation i.e.

data class Employee(UUID id);
data class Grant(UUID id, UUID grantedEmployee, UUID targetEmployee);

The query for allowed employees would consequently be:

SELECT employees.* from employees
INNER JOIN grants ON employees.id = grants.target_employee_id
WHERE grants.granted_employee_id = ?;

Thus far I have been unable to do so using spring-data-r2dbc. This is what I have tried:

  1. Using a custom query via @Query w/ SPEL. I was able to get pagination working, but there is no way to achieve dynamic sorting because there is no way to generate SQL for the requested sort.
  2. QueryDSL, which apparently is not supported.
  3. Using the fluent API, from which I cannot figure out how to achieve joins but does allow pagination and sorting.

It would be trivial to rewrite the query as:

SELECT employees.* from employees
WHERE employees.id IN (
  SELECT grants.target_employee_id from grants WHERE grants.granted_employee_id = ?
);

which could potentially be mapped to a Criteria of raw SQL, but I could not find a supporting facility.

What is the correct pattern to achieve this? The documentation seems to be lacking when it comes to JOINs.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 11, 2021
@mp911de mp911de added the for: stackoverflow A question that's better suited to stackoverflow.com label May 17, 2021
@mp911de
Copy link
Member

mp911de commented May 17, 2021

Dynamic sorting through @Query isn't supported because we don't want to get ourselves into query rewriting business. You can use DatabaseClient with your query and new EntityRowMapper<>(typeToRead,converter) (where converter is R2dbcConverter).

We do not support JOINs yet because we don't support relationships yet.

@mp911de mp911de removed the status: waiting-for-triage An issue we've not yet triaged label May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

3 participants