spring-data-r2dbc icon indicating copy to clipboard operation
spring-data-r2dbc copied to clipboard

Augment queries - add an additional filter

Open d0ivanov opened this issue 4 years ago • 4 comments

The application I'm working on is multi-tenant. The approach to tenant data isolation that all tables get an additional "tenant id" column. This results in pretty much every query having a WHERE clause like "...AND tenant_id = ". I've been evaluating the possibility of customizing query creation and processing so that this additional clause gets appended "automagically" based on the current security context. So far I've found this issue in Spring Data JPA, but it doesn't seem like there's any active development on it. So I was wondering what would be your advice on the best approach right now to appending an additional filter to every query.

d0ivanov avatar Oct 18 '21 13:10 d0ivanov

Thanks for bringing this up. Query augmentation spans a large surface as that is something to consider for derived queries as well. We first need a proper design before we can proceed in any direction. Right now we don't have much bandwidth for that issue.

mp911de avatar Oct 18 '21 14:10 mp911de

I see, thank you for your response! Granted it would be more of a patch - would you be willing to accept a change to make R2dbcQueryCreator a public class and also add a protected method in PartTreeR2dbcQuery which provides R2dbcQueryCreator instances ?

d0ivanov avatar Oct 18 '21 16:10 d0ivanov

R2dbcQueryCreator and friends are protected as we do not want to leak implementation details outside of that package. Making things public leads to usage and subclassing and that removes the ability on our side to update implementation details without breaking application code.

mp911de avatar Oct 19 '21 07:10 mp911de

@mp911de With the current feature set how would you recommend this be accomplished? I have a similar requirement where i would like to inspect each query before it is executed

jwmaher avatar Jan 16 '23 21:01 jwmaher