Rxify version
Wanna use #jooq with #reactivex on #vertx…
Stay tuned, one more step
jOOQ.x
supports out of the box almost reactive version that officially supports by Vert.x
Dependencies setup
To use jOOQ.x API
with reactive version, add the following dependency to the dependencies section of your build descriptor:
Maven
In your pom.xml
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-rx-java2</artifactId> (1)
<version>4.5.8</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-rx-java3</artifactId> (2)
<version>4.5.8</version>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-core</artifactId> (3)
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-pg-client</artifactId> (4)
<version>2.30.1</version>
</dependency>
<dependency>
<groupId>io.github.zero88</groupId>
<artifactId>jooqx</artifactId>
<version>2.0.0-rc3</version>
</dependency>
1 | For using Rx2 version |
2 | For using Rx3 version |
3 | For using mutiny version |
4 | Assume you are using pg-client |
Gradle
In your build.gradle
or build.gradle.kts
dependencies {
api("io.github.zero88:jooqx:2.0.0-rc3")
// with rx2
api("io.vertx:vertx-rx-java2:4.5.8") (1)
// or with rx3
api("io.vertx:vertx-rx-java3:4.5.8") (2)
// or with mutiny
api("io.smallrye.reactive:smallrye-mutiny-vertx-core:2.30.1") (3)
api("io.smallrye.reactive:smallrye-mutiny-vertx-pg-client:2.30.1") (4)
}
1 | For using Rx2 version |
2 | For using Rx3 version |
3 | For using mutiny version |
4 | Assume you are using pg-client |
Well done, now you can enjoy Rxify
version with a little effort
Examples
Rx2
- By jooqx
instance
SelectForUpdateStep<BooksRecord> q = jooqx.dsl()
.selectFrom(Tables.BOOKS)
.orderBy(Tables.BOOKS.TITLE)
.limit(10)
.offset(5);
// To rx-ify version
io.github.zero88.jooqx.reactivex.Jooqx rxJooqx = io.github.zero88.jooqx.reactivex.Jooqx.newInstance(jooqx);
// Rx-execute
rxJooqx.rxExecute(q, DSLAdapter.fetchMany(q.asTable())).subscribe(records -> {
BooksRecord record = records.get(0);
System.out.println(record.getId()); // output: 1
System.out.println(record.getTitle()); // output: jooqx
}, err -> { });
Rx2
- By jooqx
builder
io.vertx.reactivex.core.Vertx vertxRx2 = io.vertx.reactivex.core.Vertx.newInstance(vertx);
io.vertx.reactivex.jdbcclient.JDBCPool poolRx2 = io.vertx.reactivex.jdbcclient.JDBCPool.newInstance(pool);
// Build jOOQ query
SelectForUpdateStep<BooksRecord> q = dsl.selectFrom(Tables.BOOKS)
.orderBy(Tables.BOOKS.TITLE)
.limit(10)
.offset(5);
// Create rx2 jooqx by builder
io.github.zero88.jooqx.reactivex.Jooqx jooqx = io.github.zero88.jooqx.reactivex.Jooqx.builder()
.setVertx(vertxRx2)
.setSqlClient(poolRx2)
.setDSL(dsl)
.build();
// Rx-execute
jooqx.rxExecute(q, DSLAdapter.fetchMany(q.asTable())).subscribe(records -> {
BooksRecord record = records.get(0);
System.out.println(record.getId()); // output: 1
System.out.println(record.getTitle()); // output: jooqx
}, err -> { });
Rx3
- By jooqx
builder
io.vertx.rxjava3.core.Vertx vertxRx3 = io.vertx.rxjava3.core.Vertx.newInstance(vertx);
io.vertx.rxjava3.mysqlclient.MySQLPool poolRx3 = io.vertx.rxjava3.mysqlclient.MySQLPool.newInstance(pool);
// Build jOOQ query
SelectForUpdateStep<BooksRecord> q = dsl.selectFrom(Tables.BOOKS)
.orderBy(Tables.BOOKS.TITLE)
.limit(10)
.offset(5);
// Create rx3 jooqx by builder
io.github.zero88.jooqx.rxjava3.Jooqx jooqx = io.github.zero88.jooqx.rxjava3.Jooqx.builder()
.setVertx(vertxRx3)
.setSqlClient(poolRx3)
.setDSL(dsl)
.build();
// Rx-execute
jooqx.rxExecute(q, DSLAdapter.fetchMany(q.asTable())).subscribe(records -> {
BooksRecord record = records.get(0);
System.out.println(record.getId()); // output: 1
System.out.println(record.getTitle()); // output: jooqx
}, err -> { });
Mutiny
- By jooqx
builder
io.vertx.mutiny.core.Vertx vertxRx3 = io.vertx.mutiny.core.Vertx.newInstance(vertx);
io.vertx.mutiny.pgclient.PgPool poolRx3 = io.vertx.mutiny.pgclient.PgPool.newInstance(pool);
// Build jOOQ query
SelectForUpdateStep<BooksRecord> q = dsl.selectFrom(Tables.BOOKS)
.orderBy(Tables.BOOKS.TITLE)
.limit(10)
.offset(5);
// Create mutiny jooqx by builder
io.github.zero88.jooqx.mutiny.Jooqx jooqx = io.github.zero88.jooqx.mutiny.Jooqx.builder()
.setVertx(vertxRx3)
.setSqlClient(poolRx3)
.setDSL(dsl)
.build();
// Mutiny-execute
jooqx.execute(q, DSLAdapter.fetchMany(q.asTable())).subscribe().with(records -> {
BooksRecord record = records.get(0);
System.out.println(record.getId()); // output: 1
System.out.println(record.getTitle()); // output: jooqx
}, err -> { });