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();
});
});
});
});
}
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()));
}
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()));
}
Aggregations