Search in sources :

Example 1 with Jooqx

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);
}
Also used : Checkpoint(io.vertx.junit5.Checkpoint) Books(io.zero88.sample.data.pgsql.tables.Books) PgSQLJooqxTest(io.zero88.jooqx.spi.pg.PgSQLJooqxTest) Test(org.junit.jupiter.api.Test)

Example 2 with Jooqx

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);
}
Also used : Checkpoint(io.vertx.junit5.Checkpoint) Authors(io.zero88.sample.data.mysql.tables.Authors) Test(org.junit.jupiter.api.Test) MySQLJooqxTest(io.zero88.jooqx.spi.mysql.MySQLJooqxTest)

Example 3 with Jooqx

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());
        }
    });
}
Also used : PgConnectOptions(io.vertx.pgclient.PgConnectOptions) PgPool(io.vertx.pgclient.PgPool) Jooqx(io.zero88.jooqx.Jooqx) PoolOptions(io.vertx.sqlclient.PoolOptions) DSLContext(org.jooq.DSLContext) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord)

Example 4 with Jooqx

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"}
    });
}
Also used : Jooqx(io.zero88.jooqx.Jooqx) MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) MySQLPool(io.vertx.mysqlclient.MySQLPool) PoolOptions(io.vertx.sqlclient.PoolOptions) DSLContext(org.jooq.DSLContext) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord)

Example 5 with Jooqx

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"}]
    });
}
Also used : JDBCConnectOptions(io.vertx.jdbcclient.JDBCConnectOptions) BindBatchValues(io.zero88.jooqx.BindBatchValues) JDBCPool(io.vertx.jdbcclient.JDBCPool) Jooqx(io.zero88.jooqx.Jooqx) PoolOptions(io.vertx.sqlclient.PoolOptions) JsonRecord(io.zero88.jooqx.JsonRecord) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord)

Aggregations

PoolOptions (io.vertx.sqlclient.PoolOptions)6 Jooqx (io.zero88.jooqx.Jooqx)5 DSLContext (org.jooq.DSLContext)5 JDBCConnectOptions (io.vertx.jdbcclient.JDBCConnectOptions)4 JDBCPool (io.vertx.jdbcclient.JDBCPool)3 Checkpoint (io.vertx.junit5.Checkpoint)3 AuthorsRecord (io.zero88.sample.data.pgsql.tables.records.AuthorsRecord)3 BooksRecord (io.zero88.sample.data.pgsql.tables.records.BooksRecord)2 Record1 (org.jooq.Record1)2 Test (org.junit.jupiter.api.Test)2 VertxTestContext (io.vertx.junit5.VertxTestContext)1 MySQLConnectOptions (io.vertx.mysqlclient.MySQLConnectOptions)1 MySQLPool (io.vertx.mysqlclient.MySQLPool)1 PgConnectOptions (io.vertx.pgclient.PgConnectOptions)1 PgPool (io.vertx.pgclient.PgPool)1 BindBatchValues (io.zero88.jooqx.BindBatchValues)1 DSLAdapter (io.zero88.jooqx.DSLAdapter)1 JsonRecord (io.zero88.jooqx.JsonRecord)1 SQLExecutor (io.zero88.jooqx.SQLExecutor)1 MySQLJooqxTest (io.zero88.jooqx.spi.mysql.MySQLJooqxTest)1