Vert.x jOOQ DSL

Related tags

JSON dsl vertx jooq rql
Overview

jOOQ.x - Vertx jOOQ DSL

build GitHub release (latest SemVer) Sonatype Nexus (Releases) Sonatype Nexus (Snapshots) Lines of Code Coverage Maintainability Rating Reliability Rating Security Rating Quality Gate Status

jooqx leverages the power of typesafe SQL from jOOQ DSL and running on SQL connection in a reactive and non-blocking of SQL driver from Vert.x

Features

jooqx Provide uniform API for among

jooqx supports:

  • Lightweight and SPI
  • Typesafe
  • Native jOOQ DSL API
  • Any database with JDBC driver and combine with legacy SQL
  • Any database with Vert.x reactive client(JDBCPool is reactive JDBC driver so almost databases should work properly)
  • JsonObject record
  • Row/record transformation to jOOQ record
  • A unified format for exception and able to replace/integrate seamlessly by your current application exception
  • CRUD with prepared query by jOOQ DSL
  • SQL Complex query with typesafe such as join, with, having to, etc
  • SQL Batch insert/update/merge
  • SQL Transaction
    • [?] Nested transaction (not yet tested, but API is available)
    • Transaction rollback condition
    • Transaction annotation
  • Procedure
  • DAO
  • [?] Resource Query Language (RQL) from rsql-jooq
  • Rxified API
  • Row streaming
  • Publish/subscribe
  • Test fixtures API to easy setup test for your application testing or produce a minimum reproducer

Usage

To use jooqx add the following dependency to the dependencies section of your build descriptor:

  • Maven (in your pom.xml):
<dependency>
    <groupId>io.github.zero88</groupId>
    <artifactId>jooqx-core</artifactId>
    <version>1.0.0</version>
</dependency>
<!-- For some SPI includes specific converter based on Vert.x database client -->
<dependency>
  <groupId>io.github.zero88</groupId>
  <artifactId>jooqx-spi</artifactId>
  <version>1.0.0</version>
</dependency>
  • Gradle (in your build.gradle):
dependencies {
    api("io.github.zero88:jooqx-core:1.0.0")
    // For some SPI includes specific converter based on Vert.x database client
    api("io.github.zero88:jooqx-spi:1.0.0")
}

Hint

jooqx is only depended on 3 main libraries:

  • io.vertx:vertx-core
  • org.jooq:jooq
  • org.slf4j:slf4j-api

Adding this jooqx library JAR will not automatically add a database driver JAR to your project. You should ensure that your project also has a suitable database driver as a dependency.

For example:

  • With legacy JDBC and connecting to MySQL driver
dependencies {
    api("mysql:mysql-connector-java:8.0.23")
    // It is recommendation to use HikariCP instead of c3p0
    api("com.zaxxer:HikariCP:4.0.2")
    api("io.vertx:vertx-jdbc-client:4.0.2") {
        exclude("com.mchange")
    }
    api("io.github.zero88:jooqx-core:1.0.0")
}
  • With reactive PostgreSQL client
dependencies {
    api("io.vertx:vertx-pg-client:4.0.2")
    api("io.github.zero88:jooqx-core:1.0.0")
}
  • With reactive JDBC client and H2
dependencies {
    api("com.h2database:h2:1.4.200")
    // Agroal pool - Default in Vertx SQL client - Not yet has alternatives
    api("io.agroal:agroal-pool:1.9")
    api("io.vertx:vertx-sql-client:4.0.2")
    api("io.github.zero88:jooqx-core:1.0.0")
}

Getting started

Assume you know how to use jOOQ code generation and able to generate your database schema.

You can use: Maven jOOQ codegen or Gradle jOOQ plugin

Better experimental is my integtest to see some jOOQ generation setup

Simple query

Reactive SQL client

PgConnectOptions connectOptions = new PgConnectOptions()
  .setPort(5432)
  .setHost("the-host")
  .setDatabase("the-db")
  .setUser("user")
  .setPassword("secret");

// Pool options
PoolOptions poolOptions = new PoolOptions().setMaxSize(5);

// Create the client pool
PgPool client = PgPool.pool(connectOptions, poolOptions);

// Init jOOQ DSL context
DSLContext dslContext = DSL.using(new DefaultConfiguration().set(SQLDialect.POSTGRES));

// Build jooqx reactive sql executor
ReactiveJooqx jooqx = ReactiveJooqx.builder().vertx(vertx)
                                            .dsl(dslContext)
                                            .sqlClient(client)
                                            .build();

// It is table class in database that is generated by jOOQ
Authors table = DefaultCatalog.DEFAULT_CATALOG.DEFAULT_SCHEMA.AUTHOR;
// Start query
SelectConditionStep<Record1<Integer>> query = jooqx.dsl()
                                                .selectCount()
                                                .from(table)
                                                .where(table.COUNTRY.eq("USA"));
jooqx.execute(query, DSLAdapter.fetchCount(query.asTable()), ar ->  System.out.println(ar.result()));
//output: 10

Legacy SQL client

// Init JDBCClient legacy client
SQLClient client = JDBCClient.create(vertx, config);
DSLContext dslContext = DSL.using(new DefaultConfiguration().set(SQLDialect.H2));

// Build jooqx legacy sql executor
LegacyJooqx jooqx = LegacyJooqx.builder()
                              .vertx(Vertx.vertx())
                              .dsl(dslContext)
                              .sqlClient(client)
                              .build();

// It is table class in database that is generated by jOOQ
Authors table = DefaultCatalog.DEFAULT_CATALOG.DEFAULT_SCHEMA.AUTHOR;
// Start query
jooqx.execute(jooqx.dsl().selectFrom(table), DSLAdapter.fetchMany(table), ar -> {
    // It is AuthorRecords class that is generated by jOOQ
    AuthorRecords record = ar.result().get(0);
    System.out.println(record.getId());
    System.out.println(record.getName());
});
//output: 1
//output: zero88

Interesting? Please checkout more features, here, usage and java-doc

Contributions

Please go through on develop for how to setup environment

Short Note

Might you know, vertx-jooq is another library for vert.x and jOOQ integration was started in a longtime ago.

I already used it, too. However, in a while I realized it doesn't meet my requirements for dynamic SQL. Also, this library is narrow a power of jOOQ DSL and SQL feature likes paging, batch, transaction, complex query with join/having/group, etc. It is quite hard to extend due to mostly depends on Data Access Object (DAO) pattern, and the generation time.

Always have a different way to make it better, then I made this library to bring jOOQ DSL is first citizen and seamlessly combined with Vert.x SQL client.

Comments
Releases(jpa/v1.0.0)
Owner
zero88
Code less, do more
zero88
MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJO to JSON in a declarative way.

MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJ

Andrei Ciobanu 59 Sep 17, 2022
100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL

RuleBook » A Simple & Intuitive Rules Abstraction for Java 100% Java · Lambda Enabled · Simple, Intuitive DSL · Lightweight Why RuleBook? RuleBook rul

Delivered Technologies Labs 666 Dec 21, 2022
Java friendly DSL for defining TestFX tests

TestFX-DSL aims to bring DSL capabilities on top of TestFX. Inspired by Geb, this DSL enables a fluent interface design on top of the facilities exposed by TestFX.

Andres Almiray 5 Aug 21, 2019
JSON Library for Java with a focus on providing a clean DSL

JSON Library for Java with a focus on providing a clean DSL

Vaishnav Anil 0 Jul 11, 2022
jOOQ is the best way to write SQL in Java

jOOQ's reason for being - compared to JPA Java and SQL have come a long way. SQL is an "ancient", yet established and well-understood technology. Java

jOOQ Object Oriented Querying 5.3k Jan 4, 2023
A base repo for creating RPC microservices in Java with gRPC, jOOQ, and Maven.

Wenower Core OSX local installation Install Protocol Buffer $ brew install protobuf Install Postgresql and joopc database and user $ brew install pos

Hamidreza Soleimani 1 Jan 9, 2022
Vert.x is a tool-kit for building reactive applications on the JVM

Vert.x Core This is the repository for Vert.x core. Vert.x core contains fairly low-level functionality, including support for HTTP, TCP, file system

Eclipse Vert.x 13.3k Jan 8, 2023
A reactive dataflow engine, a data stream processing framework using Vert.x

?? NeonBee Core NeonBee is an open source reactive dataflow engine, a data stream processing framework using Vert.x. Description NeonBee abstracts mos

SAP 33 Jan 4, 2023
Consume an async api (with callback) from sync endpoint using vert.x

vertx-async-to-sync Problem statement Suppose we have two services - A and B. In a trivial and everyday scenario, client makes request to A. A then do

Tahniat Ashraf Priyam 12 Oct 19, 2022
Simple and lightweight sip server to create voice robots, based on vert.x

Overview Lightweight SIP application built on vert.x. It's intended to be used as addon for full-featured PBX to implement programmable voice scenario

Ivoice Technology 7 May 15, 2022
Vert.x PoC for Project Loom Support

Vert.x Loom Wrapper Codegen This project contains a proof of concept implementation for a codegen wrapper API that provides virtual async-await suppor

Johannes Schüth 13 Oct 10, 2022
Async Await but for Vert.x

hang-around Async Await but for Vert.x One of the main pain points of asynchronous programming is that code flow can be hard to read. With the upcomin

Paulo Lopes 12 Jul 30, 2022
Vert.x virtual threads incubator

Vert.x Virtual Threads Incubator Incubator for virtual threads based prototypes. Prerequisites Vert.x 4.3.2 Java 19 using preview feature OpenJDK 19 E

Eclipse Vert.x 89 Dec 27, 2022
Awaitility is a small Java DSL for synchronizing asynchronous operations

Testing asynchronous systems is hard. Not only does it require handling threads, timeouts and concurrency issues, but the intent of the test code can

Awaitility 3.3k Dec 31, 2022
Java DSL for easy testing of REST services

Testing and validation of REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of usi

REST Assured 6.2k Dec 31, 2022
Cucumber DSL for testing RESTful Web Services

cukes-rest takes simplicity of Cucumber and provides bindings for HTTP specification. As a sugar on top, cukes-rest adds steps for storing and using r

C.T.Co 100 Oct 18, 2022
JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.

pact-jvm JVM implementation of the consumer driven contract library pact. From the Ruby Pact website: Define a pact between service consumers and prov

Pact Foundation 962 Dec 31, 2022
A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin

Spark - a tiny web framework for Java 8 Spark 2.9.3 is out!! Changeset <dependency> <groupId>com.sparkjava</groupId> <artifactId>spark-core</a

Per Wendel 9.4k Dec 29, 2022
MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJO to JSON in a declarative way.

MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJ

Andrei Ciobanu 59 Sep 17, 2022
Awaitility is a small Java DSL for synchronizing asynchronous operations

Testing asynchronous systems is hard. Not only does it require handling threads, timeouts and concurrency issues, but the intent of the test code can

Awaitility 3.3k Jan 2, 2023