Mod to test the Database functionality

This commit is contained in:
Tina_Azure
2023-03-08 20:22:29 +01:00
parent da76fa6eef
commit 02e5910c43

View File

@ -1,23 +1,52 @@
package cavecomm;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.pgclient.PgConnectOptions;
import io.vertx.pgclient.PgPool;
import io.vertx.sqlclient.PoolOptions;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.SqlClient;
public class MainVerticle extends AbstractVerticle {
@Override
public void start() throws Exception {
// Create a Router
Router router = Router.router(vertx);
// Mount the handler for all incoming requests at every path and HTTP method
Database db = new Database(
vertx,
5432,
"localhost",
"testdb",
"testuser",
"123");
//db.executeQuery("SELECT * FROM testtable");
router.get("/jsonTest").handler(rc -> {
db.executeQuery("SELECT * FROM testtable", rc);
}
);
router.route().handler(context -> {
// Get the address of the request
String address = context.request().connection().remoteAddress().toString();
// Get the query parameter "name"
MultiMap queryParams = context.queryParams();
String name = queryParams.contains("name") ? queryParams.get("name") : "unknown";
// Write a json response
context.json(
new JsonObject()
@ -40,4 +69,4 @@ public class MainVerticle extends AbstractVerticle {
)
);
}
}
}