use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.
the class PgReABatchTest method test_batch_insert_and_returning_count.
@Test
void test_batch_insert_and_returning_count(VertxTestContext ctx) {
final Checkpoint flag = ctx.checkpoint();
final Authors table = schema().AUTHORS;
AuthorsRecord rec1 = new AuthorsRecord().setName("abc").setCountry("AU");
AuthorsRecord rec2 = new AuthorsRecord().setName("haha");
final BindBatchValues bindValues = new BindBatchValues().register(table.NAME).registerValue(table.COUNTRY, "VN").add(rec1, rec2);
final InsertSetMoreStep<AuthorsRecord> insert = jooqx.dsl().insertInto(table).set(bindValues.getDummyValues());
jooqx.batch(insert, bindValues, ar -> ctx.verify(() -> {
final BatchResult result = assertSuccess(ctx, ar);
Assertions.assertEquals(2, result.getTotal());
Assertions.assertEquals(2, result.getSuccesses());
jooqx.execute(jooqx.dsl().selectFrom(table), DSLAdapter.fetchJsonRecords(table), ar2 -> {
assertResultSize(ctx, ar2, 10);
flag.flag();
});
}));
}
use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.
the class PgReABatchTest method transaction_batch_success.
@Test
void transaction_batch_success(VertxTestContext context) {
final Checkpoint flag = context.checkpoint();
final Authors table = schema().AUTHORS;
jooqx.transaction().run(tx -> {
AuthorsRecord rec1 = new AuthorsRecord().setName("abc").setCountry("AU");
AuthorsRecord rec2 = new AuthorsRecord().setName("haha");
final BindBatchValues bindValues = new BindBatchValues().register(table.NAME).registerValue(table.COUNTRY, "VN").add(rec1, rec2);
final InsertSetMoreStep<AuthorsRecord> insert = jooqx.dsl().insertInto(table).set(bindValues.getDummyValues());
return tx.batch(insert, bindValues);
}, ar -> context.verify(() -> {
final BatchResult result = assertSuccess(context, ar);
Assertions.assertNotNull(result);
Assertions.assertEquals(2, result.getSuccesses());
Assertions.assertEquals(2, result.getTotal());
jooqx.execute(jooqx.dsl().selectFrom(table), DSLAdapter.fetchMany(table), ar2 -> {
assertResultSize(context, ar2, 10);
flag.flag();
});
}));
}
use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.
the class PgReAComplexQueryTest method test_join_2_tables_then_map_to_another_table.
@Test
void test_join_2_tables_then_map_to_another_table(VertxTestContext ctx) {
final Checkpoint flag = ctx.checkpoint();
final DSLContext dsl = jooqx.dsl();
final Public schema = schema().PUBLIC;
final SelectConditionStep<Record> query = dsl.select(schema.AUTHORS.asterisk(), schema.BOOKS_AUTHORS.BOOK_ID).from(schema.AUTHORS).join(schema.BOOKS_AUTHORS).onKey().where(schema.AUTHORS.ID.eq(4));
jooqx.execute(query, DSLAdapter.fetchMany(query.asTable(), schema.AUTHORS), ar -> ctx.verify(() -> {
final List<AuthorsRecord> records = assertResultSize(ctx, ar, 1);
final AuthorsRecord authorsRecord = records.get(0);
Assertions.assertEquals(4, authorsRecord.getId());
Assertions.assertEquals("Scott Hanselman", authorsRecord.getName());
Assertions.assertEquals("USA", authorsRecord.getCountry());
flag.flag();
}));
}
use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.
the class PgReARelationTest method test_select_one_convert_by_table.
@Test
void test_select_one_convert_by_table(VertxTestContext ctx) {
final Checkpoint flag = ctx.checkpoint();
final io.zero88.sample.data.pgsql.tables.Authors table = schema().AUTHORS;
final SelectConditionStep<AuthorsRecord> query = jooqx.dsl().selectFrom(table).where(table.COUNTRY.eq("UK"));
jooqx.execute(query, DSLAdapter.fetchOne(table), ar -> ctx.verify(() -> {
Assertions.assertTrue(ar.succeeded());
final AuthorsRecord authors = ar.result();
Assertions.assertEquals(3, authors.getId());
Assertions.assertEquals("Jane Austen", authors.getName());
Assertions.assertEquals("UK", authors.getCountry());
flag.flag();
}));
}
use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.
the class PgReARelationTest method test_select_one_but_give_query_that_returns_many.
@Test
void test_select_one_but_give_query_that_returns_many(VertxTestContext ctx) {
final Checkpoint flag = ctx.checkpoint();
final io.zero88.sample.data.pgsql.tables.Authors table = schema().AUTHORS;
final SelectForUpdateStep<AuthorsRecord> q = jooqx.dsl().selectFrom(table).where(table.COUNTRY.eq("USA")).orderBy(table.ID.desc());
jooqx.execute(q, DSLAdapter.fetchJsonRecord(q.asTable()), ar -> ctx.verify(() -> {
final JsonRecord<?> result = ar.result();
Assertions.assertNotNull(result);
Assertions.assertEquals(new JsonObject("{\"id\":8,\"name\":\"Christian Wenz\",\"country\":\"USA\"}"), result.toJson());
flag.flag();
}));
}
Aggregations