Skip to content

Commit

Permalink
WIP - managed to get bytes out from query result
Browse files Browse the repository at this point in the history
  • Loading branch information
psolomin committed Apr 28, 2023
1 parent 7308490 commit 1049e12
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public Future<SqlResult<Buffer>> copyToBytes(String sql) {
new QueryResultBuilder<>(factory, promise);

CopyOutCommand cmd = new CopyOutCommand(sql, resultHandler);
return this.schedule(promise.context(), cmd);
this.schedule(promise.context(), cmd).onComplete(resultHandler);
return promise.future();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.stream.Collector;

public class CopyOutCommand extends CommandBase<SqlResult<Buffer>> {
public class CopyOutCommand extends CommandBase<Boolean> {
private final String sql;
private final Collector<ByteBuf, Buffer, Buffer> collector;
private final QueryResultBuilder<Buffer, SqlResultImpl<Buffer>, SqlResult<Buffer>> resultHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import io.vertx.sqlclient.SqlResult;
import io.vertx.sqlclient.impl.SqlResultImpl;

class CopyOutCommandCodec extends PgCommandCodec<SqlResult<Buffer>, CopyOutCommand> {
class CopyOutCommandCodec extends PgCommandCodec<Boolean, CopyOutCommand> {
CopyOutDataDecoder decoder;

CopyOutCommandCodec(CopyOutCommand cmd) {
Expand All @@ -15,7 +15,7 @@ class CopyOutCommandCodec extends PgCommandCodec<SqlResult<Buffer>, CopyOutComma

@Override
public void handleCommandComplete(int updated) {
this.result = new SqlResultImpl<Buffer>(Buffer.buffer("abc"));
this.result = false;
Buffer result;
Throwable failure;
int size;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package io.vertx.pgclient;

import io.vertx.core.buffer.Buffer;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import org.junit.Test;

import java.util.Collections;
import java.util.List;

public class PgConnectionCopyTest extends PgConnectionTestBase {
public PgConnectionCopyTest() {
connector = (handler) -> PgConnection.connect(vertx, options).onComplete(ar -> {
Expand Down Expand Up @@ -41,7 +45,24 @@ public void testCopyToCsvBytes(TestContext ctx) {
PgConnection pgConn = (PgConnection) conn;
pgConn.copyToBytes("COPY Test TO STDOUT (FORMAT csv)")
.onComplete(ctx.asyncAssertSuccess(result -> {
result.value().getBytes();
ctx.assertNull(result.columnDescriptors());
ctx.assertEquals(10, result.rowCount());
ctx.assertEquals(10, result.size());
ctx.assertEquals(
Buffer.buffer(
"Whatever-0\n" +
"Whatever-1\n" +
"Whatever-2\n" +
"Whatever-3\n" +
"Whatever-4\n" +
"Whatever-5\n" +
"Whatever-6\n" +
"Whatever-7\n" +
"Whatever-8\n" +
"Whatever-9\n"
),
result.value()
);
async.complete();
}));
});
Expand Down

0 comments on commit 1049e12

Please sign in to comment.