Skip to content

zero88/jooqx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jOOQ.x - Vertx jOOQ DSL

jooqx 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 uses the reactive and non-blocking SQL driver from Vert.x

Examples

// Vertx part: Init Postgres client
PgConnectOptions connectOptions = new PgConnectOptions()                                (1)
  .setPort(5432)
  .setHost("the-host")
  .setDatabase("the-db")
  .setUser("user")
  .setPassword("secret");
PoolOptions poolOptions = new PoolOptions().setMaxSize(5);                              (2)
PgPool pgPool = PgPool.pool(connectOptions, poolOptions);                               (3)

// jOOQ part: Init DSL context
DSLContext dsl = DSL.using(new DefaultConfiguration().set(SQLDialect.POSTGRES));        (4)
Authors table = Tables.AUTHORS;                                                         (5)

// jooqx part: Enjoy moment
Jooqx jooqx = Jooqx.builder().setVertx(vertx).setDSL(dsl).setSqlClient(pgPool).build(); (6)
jooqx.execute(
    dsl -> dsl.select().from(table).where(table.COUNTRY.eq("VN"),                       (7)
    DSLAdapter.fetchOne(table, Collections.singletonList(table.ID, table.NAME),         (8)
    ar ->  System.out.println(ar.result())                                              (9)
);
//+----+-----------+
//|  id|name       |
//+----+-----------+
//| *88|*zero      |
//+----+-----------+
  1. Create Vertx PostgreSQL connection options

  2. Create Vertx SQL pool options

  3. Init Vertx PostgreSQL pool client

  4. Init jOOQ DSL context with Postgres dialect

  5. The example table is generated by jOOQ codegen

  6. Init jooqx instance by builder

  7. First arg: The function produces jOOQ Query by DSL context

  8. Second arg: the jooqx result adapter to convert Vertx SQL result to typesafe record in jOOQ

  9. Third arg: just simple async future handler

Interesting? Please check out documentation