Coder Social home page Coder Social logo

Comments (15)

mp911de avatar mp911de commented on May 24, 2024 1

There’s no such thing as a stupid question. We want to provide a runtime API so code can intercept and modify queries prior to execution.

from spring-data-r2dbc.

mp911de avatar mp911de commented on May 24, 2024 1

You can use it to generate events, modify the query to e.g. implement security requirements, implement multi-tenancy, add generic query predicates.

from spring-data-r2dbc.

mp911de avatar mp911de commented on May 24, 2024 1

Ideally, intercept calls execute with a custom DatabaseClient implementation that just pre-processes your sql.

from spring-data-r2dbc.

Shabin avatar Shabin commented on May 24, 2024 1

Tried doing that. Found it complicated that I had to implement all the GenericExecuteSpec, SelectFromSpec etc, for simply doing a query preprocessor.
If DefaultDatabaseClient was public I could have simply extended it.

from spring-data-r2dbc.

wellingtoncosta avatar wellingtoncosta commented on May 24, 2024

Should this be implemented at compile time or at runtime? Sorry if it is a stupid question.

from spring-data-r2dbc.

wellingtoncosta avatar wellingtoncosta commented on May 24, 2024

Got it. What kind of modifications? Optimizations? I'm so curious.

from spring-data-r2dbc.

thekalinga avatar thekalinga commented on May 24, 2024

Does this also support transparent routing of all queries to read/replica server and all CUDs to write/primary server

from spring-data-r2dbc.

mp911de avatar mp911de commented on May 24, 2024

from spring-data-r2dbc.

uaihebert avatar uaihebert commented on May 24, 2024

@mp911de is this still required? I could take a look into it.

from spring-data-r2dbc.

mp911de avatar mp911de commented on May 24, 2024

I think this ticket requires some design up-front. Looking into Spring 5's WebClient and ExchangeFunction is a good exercise to learn about delegation, filtering, and pre-/post-processing.

from spring-data-r2dbc.

mp911de avatar mp911de commented on May 24, 2024

#73 brings PreparedOperation which can form a base to encapsulate operations that should happen on a Statement (SQL-rendering and binding of values)

from spring-data-r2dbc.

Shabin avatar Shabin commented on May 24, 2024

I am migrating from a non reactive to a reactive app. I have a requirement to update all my queries with a custom value, where I replace some pattern like :id in the query with a value specific to the current execution context.
In non reactive, I had extended JdbcTemplate and intercepted all the query methods to change the sql with the required value.

public class CustomJdbcTemplate extends JdbcTemplate {
    public <T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException {
       // replace placeholders
       String statement = QueryHelper.getInstance().populateDefinedQueryPlaceHolders(sql);
       return super.query(statement, newArgTypePreparedStatementSetter(args, argTypes), rse);
   }
   //similar code in all query methods
}

What would be the correct approach for this with DatabaseClient? I assume a common query preprocessor would be a solution for this.

from spring-data-r2dbc.

crahul19 avatar crahul19 commented on May 24, 2024

Any update on if this is gonna be implemented soon? I need to add a filter like " AND someCode IN (A,B,C)" to all my queries and there's 100's of them. It would be really helpful if there was a simple way of achieving this 3-4 years after this ticket was created?

from spring-data-r2dbc.

mp911de avatar mp911de commented on May 24, 2024

The most straightforward workaround is to provide a DatabaseClient implementation that intercepts the sql(…) method, does its rewrite, and delegates to the DatabaseClient instance created by Spring.

from spring-data-r2dbc.

crahul19 avatar crahul19 commented on May 24, 2024

Do I need to use AOP for intercepting the sql(…) method of DatabaseClient? We have mostly used ReactiveCrudRepository in the DAO where we use both the @query annotation and method name for generating the query but I can use the same DatabaseClient implementation for the Repository by defining a bean of type R2dbcEntityOperations.

If you could provide some hint on how can I intercept the sql() method then that will be highly appreciated.

Thanks In Advance.

from spring-data-r2dbc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.