Search in sources :

Example 6 with PgConnectOptions

use of io.vertx.pgclient.PgConnectOptions in project vertx-examples by vert-x3.

the class SqlClientExample method start.

@Override
public void start() {
    Pool pool = PgPool.pool(vertx, new PgConnectOptions().setPort(5432).setHost("the-host").setDatabase("the-db").setUser("user").setPassword("secret"), new PoolOptions().setMaxSize(4));
    // Uncomment for MySQL
    // Pool pool = MySQLPool.pool(vertx, new MySQLConnectOptions()
    // .setPort(5432)
    // .setHost("the-host")
    // .setDatabase("the-db")
    // .setUser("user")
    // .setPassword("secret"), new PoolOptions().setMaxSize(4));
    pool.begin(res1 -> {
        if (res1.failed()) {
            System.err.println(res1.cause().getMessage());
            return;
        }
        Transaction tx = res1.result();
        // create a test table
        tx.query("create table test(id int primary key, name varchar(255))").execute(res2 -> {
            if (res2.failed()) {
                tx.close();
                System.err.println("Cannot create the table");
                res2.cause().printStackTrace();
                return;
            }
            // insert some test data
            tx.query("insert into test values (1, 'Hello'), (2, 'World')").execute(res3 -> {
                // query some data with arguments
                tx.query("select * from test").execute(rs -> {
                    if (rs.failed()) {
                        System.err.println("Cannot retrieve the data from the database");
                        rs.cause().printStackTrace();
                        return;
                    }
                    for (Row line : rs.result()) {
                        System.out.println("" + line);
                    }
                    // and close the connection
                    tx.commit();
                });
            });
        });
    });
}
Also used : PgConnectOptions(io.vertx.pgclient.PgConnectOptions) Transaction(io.vertx.sqlclient.Transaction) PoolOptions(io.vertx.sqlclient.PoolOptions) PgPool(io.vertx.pgclient.PgPool) Pool(io.vertx.sqlclient.Pool) Row(io.vertx.sqlclient.Row)

Example 7 with PgConnectOptions

use of io.vertx.pgclient.PgConnectOptions in project raml-module-builder by folio-org.

the class PostgresClientTest method testPgConnectOptionsEmpty.

@Test
public void testPgConnectOptionsEmpty() {
    JsonObject conf = new JsonObject();
    PgConnectOptions options = PostgresClient.createPgConnectOptions(conf);
    assertThat("localhost", is(options.getHost()));
    assertThat(5432, is(options.getPort()));
    assertThat("user", is(options.getUser()));
    assertThat("pass", is(options.getPassword()));
    assertThat("db", is(options.getDatabase()));
// TODO: enable when available in vertx-sql-client/vertx-pg-client
// https://issues.folio.org/browse/RMB-657
// assertThat(60000, is(options.getConnectionReleaseDelay()));
}
Also used : PgConnectOptions(io.vertx.pgclient.PgConnectOptions) JsonObject(io.vertx.core.json.JsonObject) AESTest(org.folio.rest.security.AESTest) Test(org.junit.Test)

Example 8 with PgConnectOptions

use of io.vertx.pgclient.PgConnectOptions in project raml-module-builder by folio-org.

the class PostgresClientTest method testPgConnectOptionsFull.

@Test
public void testPgConnectOptionsFull() {
    JsonObject conf = new JsonObject().put("host", "myhost").put("port", 5433).put("username", "myuser").put("password", "mypassword").put("database", "mydatabase").put("connectionReleaseDelay", 1000);
    PgConnectOptions options = PostgresClient.createPgConnectOptions(conf);
    assertThat("myhost", is(options.getHost()));
    assertThat(5433, is(options.getPort()));
    assertThat("myuser", is(options.getUser()));
    assertThat("mypassword", is(options.getPassword()));
    assertThat("mydatabase", is(options.getDatabase()));
// TODO: enable when available in vertx-sql-client/vertx-pg-client
// https://issues.folio.org/browse/RMB-657
// assertThat(1000, is(options.getConnectionReleaseDelay()));
}
Also used : PgConnectOptions(io.vertx.pgclient.PgConnectOptions) JsonObject(io.vertx.core.json.JsonObject) AESTest(org.folio.rest.security.AESTest) Test(org.junit.Test)

Aggregations

PgConnectOptions (io.vertx.pgclient.PgConnectOptions)8 PoolOptions (io.vertx.sqlclient.PoolOptions)5 PgPool (io.vertx.pgclient.PgPool)4 Pool (io.vertx.sqlclient.Pool)4 Row (io.vertx.sqlclient.Row)4 JsonObject (io.vertx.core.json.JsonObject)2 SqlConnection (io.vertx.sqlclient.SqlConnection)2 Transaction (io.vertx.sqlclient.Transaction)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AESTest (org.folio.rest.security.AESTest)2 Test (org.junit.Test)2 JdkSSLEngineOptions (io.vertx.core.net.JdkSSLEngineOptions)1 OpenSSLEngineOptions (io.vertx.core.net.OpenSSLEngineOptions)1 PemTrustOptions (io.vertx.core.net.PemTrustOptions)1