Search in sources :

Example 1 with Pool

use of io.vertx.mutiny.sqlclient.Pool in project smallrye-mutiny-vertx-bindings by smallrye.

the class DB2ClientTest method testTransaction.

@Test
public void testTransaction() {
    DB2ConnectOptions options = new DB2ConnectOptions().setPort(container.getMappedPort(50000)).setHost(container.getContainerIpAddress()).setDatabase(container.getDatabaseName()).setUser(container.getUsername()).setPassword(container.getPassword());
    Pool client = DB2Pool.pool(vertx, options, new PoolOptions().setMaxSize(5));
    Uni<Void> uni = client.getConnection().onItem().transformToUni(c -> {
        return c.begin().onItem().transformToUni(tx -> c.query("SELECT 1 FROM SYSIBM.SYSDUMMY1").execute().call(() -> c.query("SELECT 1 FROM SYSIBM.SYSDUMMY1").execute()).onItem().transformToUni(results -> tx.commit()).onFailure().recoverWithUni(t -> tx.rollback()));
    });
    Void v = uni.await().indefinitely();
    assertThat(v).isNull();
}
Also used : Pool(io.vertx.mutiny.sqlclient.Pool) Db2Container(org.testcontainers.containers.Db2Container) Tuple2(io.smallrye.mutiny.tuples.Tuple2) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DB2Pool(io.vertx.mutiny.db2client.DB2Pool) Test(org.junit.Test) Uni(io.smallrye.mutiny.Uni) PoolOptions(io.vertx.sqlclient.PoolOptions) After(org.junit.After) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) Vertx(io.vertx.mutiny.core.Vertx) Row(io.vertx.mutiny.sqlclient.Row) ClassRule(org.junit.ClassRule) Before(org.junit.Before) RowSet(io.vertx.mutiny.sqlclient.RowSet) PoolOptions(io.vertx.sqlclient.PoolOptions) DB2ConnectOptions(io.vertx.db2client.DB2ConnectOptions) Pool(io.vertx.mutiny.sqlclient.Pool) DB2Pool(io.vertx.mutiny.db2client.DB2Pool) Test(org.junit.Test)

Example 2 with Pool

use of io.vertx.mutiny.sqlclient.Pool in project smallrye-mutiny-vertx-bindings by smallrye.

the class PostGreSQLClientTest method testMutinyAPI.

@Test
public void testMutinyAPI() {
    PgConnectOptions options = new PgConnectOptions().setPort(container.getMappedPort(5432)).setHost(container.getContainerIpAddress()).setDatabase(container.getDatabaseName()).setUser(container.getUsername()).setPassword(container.getPassword());
    Pool client = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(5));
    RowSet<?> join = client.query("SELECT 1").executeAndAwait();
    assertThat(join).isNotNull();
    assertThat(join.size()).isEqualTo(1);
}
Also used : PgConnectOptions(io.vertx.pgclient.PgConnectOptions) PoolOptions(io.vertx.sqlclient.PoolOptions) PgPool(io.vertx.mutiny.pgclient.PgPool) Pool(io.vertx.mutiny.sqlclient.Pool)

Example 3 with Pool

use of io.vertx.mutiny.sqlclient.Pool in project smallrye-mutiny-vertx-bindings by smallrye.

the class PostGreSQLClientTest method testSequence.

@Test
public void testSequence() {
    PgConnectOptions options = new PgConnectOptions().setPort(container.getMappedPort(5432)).setHost(container.getContainerIpAddress()).setDatabase(container.getDatabaseName()).setUser(container.getUsername()).setPassword(container.getPassword());
    Pool client = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(5));
    Uni<Tuple2<RowSet<Row>, RowSet<Row>>> uni = client.getConnection().flatMap(c -> Uni.combine().all().unis(c.preparedQuery("SELECT 1").execute(), c.preparedQuery("SELECT 1").execute()).asTuple());
    Tuple2<RowSet<Row>, RowSet<Row>> results = uni.await().indefinitely();
    assertThat(results).isNotNull();
    assertThat(results.size()).isEqualTo(2);
    assertThat(results.getItem1()).isNotNull();
    assertThat(results.getItem2()).isNotNull();
}
Also used : PgConnectOptions(io.vertx.pgclient.PgConnectOptions) Tuple2(io.smallrye.mutiny.tuples.Tuple2) PoolOptions(io.vertx.sqlclient.PoolOptions) RowSet(io.vertx.mutiny.sqlclient.RowSet) PgPool(io.vertx.mutiny.pgclient.PgPool) Pool(io.vertx.mutiny.sqlclient.Pool) Row(io.vertx.mutiny.sqlclient.Row)

Example 4 with Pool

use of io.vertx.mutiny.sqlclient.Pool in project smallrye-mutiny-vertx-bindings by smallrye.

the class MySQLClientTest method testMutinyAPI.

@Test
public void testMutinyAPI() {
    MySQLConnectOptions options = new MySQLConnectOptions().setPort(container.getMappedPort(3306)).setHost(container.getContainerIpAddress()).setDatabase(MYSQL_DATABASE).setUser("root").setPassword(MYSQL_ROOT_PASSWORD);
    Pool client = MySQLPool.pool(vertx, options, new PoolOptions().setMaxSize(5));
    RowSet<?> join = client.query("SELECT 1").executeAndAwait();
    assertThat(join).isNotNull();
    assertThat(join.size()).isEqualTo(1);
}
Also used : MySQLConnectOptions(io.vertx.mysqlclient.MySQLConnectOptions) PoolOptions(io.vertx.sqlclient.PoolOptions) Pool(io.vertx.mutiny.sqlclient.Pool) MySQLPool(io.vertx.mutiny.mysqlclient.MySQLPool)

Example 5 with Pool

use of io.vertx.mutiny.sqlclient.Pool in project smallrye-mutiny-vertx-bindings by smallrye.

the class SqlClientTemplateTest method test.

@Test
public void test() {
    PgConnectOptions options = new PgConnectOptions().setPort(container.getMappedPort(5432)).setHost(container.getContainerIpAddress()).setDatabase(container.getDatabaseName()).setUser(container.getUsername()).setPassword(container.getPassword());
    Pool client = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(5));
    Map<String, Object> parameters = Collections.singletonMap("id", 1);
    assertThatThrownBy(() -> SqlTemplate.forQuery(client, "SELECT * FROM users WHERE id=#{id}").executeAndAwait(parameters)).isInstanceOf(// Table not created.
    PgException.class);
}
Also used : PgConnectOptions(io.vertx.pgclient.PgConnectOptions) PoolOptions(io.vertx.sqlclient.PoolOptions) Pool(io.vertx.mutiny.sqlclient.Pool) PgPool(io.vertx.mutiny.pgclient.PgPool) Test(org.junit.Test)

Aggregations

Pool (io.vertx.mutiny.sqlclient.Pool)8 PoolOptions (io.vertx.sqlclient.PoolOptions)8 Tuple2 (io.smallrye.mutiny.tuples.Tuple2)4 PgPool (io.vertx.mutiny.pgclient.PgPool)4 Row (io.vertx.mutiny.sqlclient.Row)4 RowSet (io.vertx.mutiny.sqlclient.RowSet)4 PgConnectOptions (io.vertx.pgclient.PgConnectOptions)4 Test (org.junit.Test)4 DB2ConnectOptions (io.vertx.db2client.DB2ConnectOptions)3 DB2Pool (io.vertx.mutiny.db2client.DB2Pool)3 Uni (io.smallrye.mutiny.Uni)2 Vertx (io.vertx.mutiny.core.Vertx)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 MySQLPool (io.vertx.mutiny.mysqlclient.MySQLPool)1 MySQLConnectOptions (io.vertx.mysqlclient.MySQLConnectOptions)1 org.junit (org.junit)1 After (org.junit.After)1 Before (org.junit.Before)1 ClassRule (org.junit.ClassRule)1 Db2Container (org.testcontainers.containers.Db2Container)1