// 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 |
//+----+-----------+
-
Create
Vertx
PostgreSQL connection options -
Create
Vertx
SQL pool options -
Init
Vertx
PostgreSQL pool client -
Init
jOOQ
DSL context withPostgres
dialect -
The example table is generated by
jOOQ
codegen -
Init
jooqx
instance by builder -
Second arg: the jooqx result adapter to convert
Vertx
SQL result to typesafe record injOOQ
-
Third arg: just simple async future handler
Interesting? Please check out documentation