Git Product home page Git Product logo

vertx-jooq's Introduction

vertx-jooq

A jOOQ-CodeGenerator to create vertx-ified DAOs and POJOs! Perform all CRUD-operations asynchronously and convert your POJOs from/into a io.vertx.core.json.JsonObject using the API and driver of your choice.

latest release 6.5.5

  • Fix Use enum literal instead of toString for datatype conversion #209
  • Update to jooq 3.17.3
  • Update to vertx 4.3.3
  • Update mutiny dependencies
  • Update rx dependencies

different needs, different apis

What do you want

Before you start generating code using vertx-jooq, you have to answer these questions:

  • Which API do you want to use?
    • a io.vertx.core.Future-based API. This is vertx-jooq-classic.
    • a rxjava2 based API. This is vertx-jooq-rx.
    • a rxjava3 based API. This is vertx-jooq-rx3.
    • a mutiny based API. This is vertx-jooq-mutiny.
  • How do you want to communicate with the database?
    • Using good old JDBC, check for the modules with -jdbc suffix.
    • Using the reactive vertx database driver, check for -reactive modules.
  • Do you need extras?
    • Support for Guice dependency injection
    • Generation of io.vertx.codegen.annotations.@DataObject-annotations for your POJOs

Once you made your choice, you can start to configure the code-generator. This can be either done programmatically or using a maven- / gradle-plugin (recommended way). Please check the documentation in the module of the API and driver of your choice how to set it up and how to use it:

example

Once the generator is set up, it can create DAOs like in the code snippet below (classic-API, JDBC, no dependency injection):

//Setup your jOOQ configuration
Configuration configuration = ...

//setup Vertx
Vertx vertx = Vertx.vertx();

//instantiate a DAO (which is generated for you)
SomethingDao dao = new SomethingDao(configuration,vertx);

//fetch something with ID 123...
dao.findOneById(123)
    .onComplete(res->{
    		if(res.succeeded()){
        		vertx.eventBus().send("sendSomething", res.result().toJson())
    		}else{
    				System.err.println("Something failed badly: "+res.cause().getMessage());
    		}
    });

//maybe consume it in another verticle
vertx.eventBus().<JsonObject>consumer("sendSomething", jsonEvent->{
    JsonObject message = jsonEvent.body();
    //Convert it back into a POJO...
    Something something = new Something(message);
    //... change some values
    something.setSomeregularnumber(456);
    //... and update it into the DB
    Future<Integer> updatedFuture = dao.update(something);
});

//or do you prefer writing your own type-safe SQL? Use the QueryExecutor from the DAO...
ClassicQueryExecutor queryExecutor = dao.queryExecutor();
//... or create a new one when there is no DAO around :)
queryExecutor = new JDBCClassicGenericQueryExecutor(configuration,vertx);
Future<Integer> updatedCustom = queryExecutor.execute(dslContext ->
				dslContext
				.update(Tables.SOMETHING)
				.set(Tables.SOMETHING.SOMEREGULARNUMBER,456)
				.where(Tables.SOMETHING.SOMEID.eq(something.getSomeid()))
				.execute()
);

//check for completion
updatedCustom.onComplete(res->{
		if(res.succeeded()){
				System.out.println("Rows updated: "+res.result());
		}else{
				System.err.println("Something failed badly: "+res.cause().getMessage());
		}
});

More examples can be found here, here and here.

FAQ

vertx is cool, but what about quarkus?

Checkout this repository to figure out how to utilize vertx-jooq to create Quarkus-compatible classes.

handling custom datatypes

The generator will omit datatypes that it does not know, e.g. java.sql.Timestamp. To fix this, you can subclass the generator, handle these types and generate the code using your generator. See the handleCustomTypeFromJson and handleCustomTypeToJson methods in the AbstractVertxGenerator or checkout the CustomVertxGenerator from the tests.

is vertx-jooq compatible with Java 8?

Starting with version 6.4.0, vertx-jooq implicitly requires Java 11, as this is the minimum required version by the non-commercial version of jOOQ 3.15. If you're stuck with Java 8, the latest version you can use is 6.3.0.

are you sure this works?

Yes! There are many integration tests that cover most usecases. Check them out if you're interested.

how to run tests

The tests are executed against two docker containers. Please refer to this readme of how to set them up.

I receive a "Too many open files" exception on macOS

Increase your file limits. Unfortunately the solution differs by each OS version, so you have to do some research.

disclaimer

This library comes without any warranty - just take it or leave it. Also, the author is neither connected to the company behind vertx nor the one behind jOOQ.

vertx-jooq's People

Contributors

bentatham avatar cdekok avatar cescoffier avatar dependabot[bot] avatar doctorpangloss avatar dreamkidd avatar guss77 avatar jamieps avatar jasminsuljic avatar jklingsporn avatar jotschi avatar m1schka avatar mykelalvis avatar oresoftware avatar quen2404 avatar romanbsd avatar ukonnra avatar vmaubert avatar weisslertal avatar

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.