use of io.zero88.jooqx.Jooqx in project jooqx by zero88.
the class PgReARxTest method test_simple_rx.
@Test
void test_simple_rx(VertxTestContext ctx) {
final Books table = schema().BOOKS;
Checkpoint cp = ctx.checkpoint();
rxPool(jooqx).rxExecute(jooqx.dsl().selectFrom(table), DSLAdapter.fetchJsonRecords(table)).subscribe(recs -> {
ctx.verify(() -> Assertions.assertEquals(7, recs.size()));
cp.flag();
}, ctx::failNow);
}
use of io.zero88.jooqx.Jooqx in project jooqx by zero88.
the class MySQLReARxTest method test_query_authors.
@Test
void test_query_authors(VertxTestContext ctx) {
final Authors table = schema().AUTHORS;
Checkpoint cp = ctx.checkpoint();
rxPool(jooqx).rxExecute(jooqx.dsl().selectFrom(table), DSLAdapter.fetchJsonRecords(table)).subscribe(recs -> {
ctx.verify(() -> Assertions.assertEquals(7, recs.size()));
cp.flag();
}, ctx::failNow);
}
use of io.zero88.jooqx.Jooqx in project jooqx by zero88.
the class JooqxFeature method future.
public void future(Vertx vertx) {
// Pg connection
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 pool from the data object
PgPool pgPool = PgPool.pool(vertx, connectOptions, poolOptions);
// jOOQ DSL
DSLContext dsl = DSL.using(SQLDialect.POSTGRES);
// Build jOOQ query
Jooqx jooqx = Jooqx.builder().setVertx(vertx).setDSL(dsl).setSqlClient(pgPool).build();
// Build jOOQx
SelectConditionStep<AuthorsRecord> q = dsl.selectFrom(Tables.AUTHORS).where(Tables.AUTHORS.NAME.eq("zero88"));
// Execute
jooqx.execute(q, DSLAdapter.fetchOne(q.asTable()), ar -> {
if (ar.succeeded()) {
AuthorsRecord rec = ar.result();
System.out.println(rec.getName());
System.out.println(rec.getCountry());
}
});
}
use of io.zero88.jooqx.Jooqx in project jooqx by zero88.
the class JooqxFeature method jsonRecord.
/**
* Vertx JsonObject vs jOOQ Record... Ya, merging: JsonRecord
*/
@Override
public void jsonRecord(Vertx vertx) {
MySQLConnectOptions connectOptions = new MySQLConnectOptions().setPort(3306).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret");
MySQLPool mySQLPool = MySQLPool.pool(vertx, connectOptions, new PoolOptions().setMaxSize(5));
// jOOQ DSL
DSLContext dsl = DSL.using(SQLDialect.MYSQL);
// Build jOOQ query
SelectForUpdateStep<AuthorsRecord> q = dsl.selectFrom(Tables.AUTHORS).where(Tables.AUTHORS.NAME.eq("zero88")).limit(1).offset(1);
// Build jOOQx
Jooqx jooqx = Jooqx.builder().setVertx(vertx).setDSL(dsl).setSqlClient(mySQLPool).build();
jooqx.execute(q, DSLAdapter.fetchJsonRecord(q.asTable()), ar -> {
System.out.println(ar.result().toJson());
// output: {"id":88,"name":"zero88","country":"VN"}
});
}
use of io.zero88.jooqx.Jooqx in project jooqx by zero88.
the class JooqxFeature method batch.
@Override
public void batch(Vertx vertx) {
JDBCPool pool = JDBCPool.pool(vertx, new JDBCConnectOptions().setJdbcUrl("jdbc:h2:mem:jooqx-examples"), new PoolOptions().setMaxSize(5));
// Build jOOQx
Jooqx jooqx = Jooqx.builder().setVertx(vertx).setDSL(DSL.using(SQLDialect.H2)).setSqlClient(pool).build();
AuthorsRecord rec1 = new AuthorsRecord().setName("zero88").setCountry("VN");
AuthorsRecord rec2 = new AuthorsRecord().setName("jooq").setCountry("CH");
AuthorsRecord rec3 = new AuthorsRecord().setName("vertx");
BindBatchValues bindValues = new BindBatchValues().register(Tables.AUTHORS.NAME).registerValue(Tables.AUTHORS.COUNTRY, "FR").add(rec1, rec2, rec3);
InsertResultStep<AuthorsRecord> insert = jooqx.dsl().insertInto(Tables.AUTHORS).set(bindValues.getDummyValues()).returning();
// Wanna know success number
jooqx.batch(insert, bindValues, ar -> {
// 3
System.out.println(ar.result().getTotal());
// 3
System.out.println(ar.result().getSuccesses());
});
// Wanna get detail
jooqx.batch(insert, bindValues, DSLAdapter.fetchJsonRecords(Tables.AUTHORS), ar -> {
System.out.println(ar.result().getRecords().stream().map(JsonRecord::toJson).collect(Collectors.toList()));
// [{"id":1,"name":"zero88","country":"VN"},{"id":2,"name":"jooq","country":"CH"},{"id":3,"name":"vertx",
// "country":"FR"}]
});
}
Aggregations