Skip to content

Commit

Permalink
Change methods' signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
psolomin committed Apr 19, 2023
1 parent d7a4b28 commit 1930343
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
12 changes: 4 additions & 8 deletions vertx-pg-client/src/main/java/examples/PgClientExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.buffer.impl.BufferImpl;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.PemTrustOptions;
import io.vertx.docgen.Source;
Expand Down Expand Up @@ -738,7 +736,7 @@ public void batchReturning(SqlClient client) {
public void importDataToDb(Vertx vertx, PgConnection client) {
vertx.fileSystem().readFile("path/to/file")
.flatMap(bufferAsyncResult -> {
return client.copyFrom(
return client.copyFromBytes(
"COPY my_table FROM STDIN (FORMAT csv, HEADER)",
bufferAsyncResult
).execute();
Expand All @@ -749,12 +747,10 @@ public void importDataToDb(Vertx vertx, PgConnection client) {
}

public void exportDataFromDb(Vertx vertx, PgConnection client) {
Buffer buffer = new BufferImpl();
String path = "path/to/file";
client.copyTo("COPY my_table TO STDOUT (FORMAT csv, HEADER)", buffer)
.andThen(res -> {
vertx.fileSystem().writeFile("path/to/file.csv", buffer);
}).onSuccess(res -> System.out.println("Data exported to " + path));
client.copyToBytes("COPY my_table TO STDOUT (FORMAT csv, HEADER)").execute()
.flatMap(buffer -> vertx.fileSystem().writeFile("path/to/file.csv", buffer))
.onSuccess(res -> System.out.println("Data exported to " + path));
}

public void pgBouncer(PgConnectOptions connectOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static Future<PgConnection> connect(Vertx vertx, String connectionUri) {
* @param from byte stream data will be fetched from
* @return result set with single field {@code rowsWritten}
*/
Query<RowSet<Row>> copyFrom(String sql, Buffer from);
Query<RowSet<Row>> copyFromBytes(String sql, Buffer from);

/**
* Exports data from a database with decoding.
Expand All @@ -118,18 +118,17 @@ static Future<PgConnection> connect(Vertx vertx, String connectionUri) {
* @param sql COPY command (example {@code COPY my_table TO STDOUT (FORMAT binary)})
* @return decoded records
*/
Query<RowSet<Row>> copyTo(String sql);
Query<RowSet<Row>> copyToRows(String sql);

/**
* Exports data from a database as-is, without decoding.
*
* <p>Use this method when exporting opaque bytes, e.g. to a CSV file.
*
* @param sql COPY command (example {@code COPY my_table TO STDOUT (FORMAT csv)})
* @param to bytes container data will be written to
* @return async result
* @return async result of bytes container data will be written to
*/
Future<Void> copyTo(String sql, Buffer to);
Query<Buffer> copyToBytes(String sql);

/**
* Send a request cancellation message to tell the server to cancel processing request in this connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ public PgConnection noticeHandler(Handler<PgNotice> handler) {
}

@Override
public Query<RowSet<Row>> copyFrom(String sql, Buffer from) {
public Query<RowSet<Row>> copyFromBytes(String sql, Buffer from) {
return null;
}

@Override
public Query<RowSet<Row>> copyTo(String sql) {
public Query<RowSet<Row>> copyToRows(String sql) {
return null;
}

@Override
public Future<Void> copyTo(String sql, Buffer to) {
return Future.succeededFuture();
public Query<Buffer> copyToBytes(String sql) {
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void testCopyToRows(TestContext ctx) {
deleteFromTestTable(ctx, conn, () -> {
insertIntoTestTable(ctx, conn, 10, () -> {
PgConnection pgConn = (PgConnection) conn;
pgConn.copyTo("COPY my_table TO STDOUT (FORMAT binary)")
pgConn.copyToRows("COPY my_table TO STDOUT (FORMAT binary)")
.execute()
.onComplete(ctx.asyncAssertSuccess(result -> {
for (int i = 0; i < 2; i++) {
Expand Down

0 comments on commit 1930343

Please sign in to comment.