Mod to test the Database functionality
This commit is contained in:
@ -1,23 +1,52 @@
|
|||||||
package cavecomm;
|
package cavecomm;
|
||||||
|
|
||||||
import io.vertx.core.AbstractVerticle;
|
import io.vertx.core.AbstractVerticle;
|
||||||
|
import io.vertx.core.AsyncResult;
|
||||||
|
import io.vertx.core.Handler;
|
||||||
import io.vertx.core.MultiMap;
|
import io.vertx.core.MultiMap;
|
||||||
import io.vertx.core.json.JsonObject;
|
import io.vertx.core.json.JsonObject;
|
||||||
import io.vertx.ext.web.Router;
|
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 {
|
public class MainVerticle extends AbstractVerticle {
|
||||||
@Override
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
// Create a Router
|
// Create a Router
|
||||||
Router router = Router.router(vertx);
|
Router router = Router.router(vertx);
|
||||||
|
|
||||||
// Mount the handler for all incoming requests at every path and HTTP method
|
// 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 -> {
|
router.route().handler(context -> {
|
||||||
// Get the address of the request
|
// Get the address of the request
|
||||||
String address = context.request().connection().remoteAddress().toString();
|
String address = context.request().connection().remoteAddress().toString();
|
||||||
// Get the query parameter "name"
|
// Get the query parameter "name"
|
||||||
MultiMap queryParams = context.queryParams();
|
MultiMap queryParams = context.queryParams();
|
||||||
String name = queryParams.contains("name") ? queryParams.get("name") : "unknown";
|
String name = queryParams.contains("name") ? queryParams.get("name") : "unknown";
|
||||||
|
|
||||||
|
|
||||||
// Write a json response
|
// Write a json response
|
||||||
context.json(
|
context.json(
|
||||||
new JsonObject()
|
new JsonObject()
|
||||||
@ -40,4 +69,4 @@ public class MainVerticle extends AbstractVerticle {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user