jklingsporn / vertx-jooq

A jOOQ-CodeGenerator to create vertx-ified DAOs and POJOs.
MIT License
385 stars 53 forks source link

Create method to execute arbitrary SQL for reactive query executors #144

Closed jklingsporn closed 4 years ago

jklingsporn commented 4 years ago

Currently, there is no way to perform an INSERT RETURNING * for the reactive query executors. Reason being is that the findOne/findMany-methods are taking a ResultQuery, but the actual INSERT RETURNING returns a UpdateResultStep. We cannot relax the method parameter of the findOne/findMany-methods to Query because otherwise we would encourage users to submit an UPDATE or DELETE query.

With the following method the user could execute any query:

public Future<RowSet<Row>> executeRaw(Function<DSLContext, ? extends Query> queryFunction) {
        Query query = createQuery(queryFunction);
        log(query);
        Promise<RowSet<Row>> rowPromise = Promise.promise();
        delegate.preparedQuery(toPreparedQuery(query)).execute(getBindValues(query),rowPromise);
        return rowPromise.future();
    }

If required, mapping the Row into a POJO can be done using the right RowMapper.