// Path: src/main/java/io/vertx/ext/sql/impl/RowStreamWrapper.java
// public class RowStreamWrapper implements SQLRowStream {
// 
//   private final SQLConnection connection;
//   private final SQLRowStream rowStream;
// 
//   public RowStreamWrapper(SQLConnection connection, SQLRowStream rowStream) {
//     this.connection = connection;
//     this.rowStream = rowStream;
//   }
// 
//   private void closeConnection(Handler<AsyncResult<Void>> handler) {
//     connection.close(handler);
//   }
// 
//   @Override
//   public SQLRowStream exceptionHandler(Handler<Throwable> handler) {
//     if (handler == null) {
//       rowStream.exceptionHandler(h1 -> closeConnection(h2 -> {}));
//     } else {
//       rowStream.exceptionHandler(h1 -> closeConnection(h2 -> handler.handle(h1)));
//     }
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream handler(Handler<JsonArray> handler) {
//     rowStream.handler(handler);
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream fetch(long amount) {
//     rowStream.fetch(amount);
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream pause() {
//     rowStream.pause();
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream resume() {
//     rowStream.resume();
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream endHandler(Handler<Void> endHandler) {
//     if (endHandler == null) {
//       rowStream.endHandler(h1 -> closeConnection(h2 -> {}));
//     } else {
//       rowStream.endHandler(h1 -> closeConnection(h2 -> endHandler.handle(h1)));
//     }
//     return this;
//   }
// 
//   @Override
//   public int column(String name) {
//     return rowStream.column(name);
//   }
// 
//   @Override
//   public List<String> columns() {
//     return rowStream.columns();
//   }
// 
//   @Override
//   public SQLRowStream resultSetClosedHandler(Handler<Void> handler) {
//     rowStream.resultSetClosedHandler(handler);
//     return this;
//   }
// 
//   @Override
//   public void moreResults() {
//     rowStream.moreResults();
//   }
// 
//   @Override
//   public void close() {
//     close(null);
//   }
// 
//   @Override
//   public void close(Handler<AsyncResult<Void>> handler) {
//     rowStream.close(h1 -> closeConnection(h2 -> {
//       if (handler != null) {
//         handler.handle(h1);
//       }
//     }));
//   }
// }


import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.json.JsonArray;
import io.vertx.ext.sql.impl.RowStreamWrapper;
    return this;
  }

  /**
   * Executes the given SQL <code>SELECT</code> statement which returns the results of the query as a read stream.
   *
   * @param sql  the SQL to execute. For example <code>SELECT * FROM table ...</code>.
   * @param handler  the handler which is called once the operation completes. It will return a {@code SQLRowStream}.
   *
   * @see java.sql.Statement#executeQuery(String)
   * @see java.sql.PreparedStatement#executeQuery(String)
   */
  @Fluent
  @Override
  default SQLClient queryStream(String sql, Handler<AsyncResult<SQLRowStream>> handler) {
    getConnection(getConnection -> {
      if (getConnection.failed()) {
        handler.handle(Future.failedFuture(getConnection.cause()));
      } else {
        final SQLConnection conn = getConnection.result();
        conn.queryStream(sql, query -> {
          if (query.failed()) {
            conn.close(close -> {
              if (close.failed()) {
                handler.handle(Future.failedFuture(close.cause()));
              } else {
                handler.handle(Future.failedFuture(query.cause()));
              }
            });
          } else {
// Path: src/main/java/io/vertx/ext/sql/impl/RowStreamWrapper.java
// public class RowStreamWrapper implements SQLRowStream {
// 
//   private final SQLConnection connection;
//   private final SQLRowStream rowStream;
// 
//   public RowStreamWrapper(SQLConnection connection, SQLRowStream rowStream) {
//     this.connection = connection;
//     this.rowStream = rowStream;
//   }
// 
//   private void closeConnection(Handler<AsyncResult<Void>> handler) {
//     connection.close(handler);
//   }
// 
//   @Override
//   public SQLRowStream exceptionHandler(Handler<Throwable> handler) {
//     if (handler == null) {
//       rowStream.exceptionHandler(h1 -> closeConnection(h2 -> {}));
//     } else {
//       rowStream.exceptionHandler(h1 -> closeConnection(h2 -> handler.handle(h1)));
//     }
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream handler(Handler<JsonArray> handler) {
//     rowStream.handler(handler);
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream fetch(long amount) {
//     rowStream.fetch(amount);
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream pause() {
//     rowStream.pause();
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream resume() {
//     rowStream.resume();
//     return this;
//   }
// 
//   @Override
//   public SQLRowStream endHandler(Handler<Void> endHandler) {
//     if (endHandler == null) {
//       rowStream.endHandler(h1 -> closeConnection(h2 -> {}));
//     } else {
//       rowStream.endHandler(h1 -> closeConnection(h2 -> endHandler.handle(h1)));
//     }
//     return this;
//   }
// 
//   @Override
//   public int column(String name) {
//     return rowStream.column(name);
//   }
// 
//   @Override
//   public List<String> columns() {
//     return rowStream.columns();
//   }
// 
//   @Override
//   public SQLRowStream resultSetClosedHandler(Handler<Void> handler) {
//     rowStream.resultSetClosedHandler(handler);
//     return this;
//   }
// 
//   @Override
//   public void moreResults() {
//     rowStream.moreResults();
//   }
// 
//   @Override
//   public void close() {
//     close(null);
//   }
// 
//   @Override
//   public void close(Handler<AsyncResult<Void>> handler) {
//     rowStream.close(h1 -> closeConnection(h2 -> {
//       if (handler != null) {
//         handler.handle(h1);
//       }
//     }));
//   }
// }


// Path: src/main/java/io/vertx/ext/sql/SQLClient.java
import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.json.JsonArray;
import io.vertx.ext.sql.impl.RowStreamWrapper;

    return this;
  }

  /**
   * Executes the given SQL <code>SELECT</code> statement which returns the results of the query as a read stream.
   *
   * @param sql  the SQL to execute. For example <code>SELECT * FROM table ...</code>.
   * @param handler  the handler which is called once the operation completes. It will return a {@code SQLRowStream}.
   *
   * @see java.sql.Statement#executeQuery(String)
   * @see java.sql.PreparedStatement#executeQuery(String)
   */
  @Fluent
  @Override
  default SQLClient queryStream(String sql, Handler<AsyncResult<SQLRowStream>> handler) {
    getConnection(getConnection -> {
      if (getConnection.failed()) {
        handler.handle(Future.failedFuture(getConnection.cause()));
      } else {
        final SQLConnection conn = getConnection.result();
        conn.queryStream(sql, query -> {
          if (query.failed()) {
            conn.close(close -> {
              if (close.failed()) {
                handler.handle(Future.failedFuture(close.cause()));
              } else {
                handler.handle(Future.failedFuture(query.cause()));
              }
            });
          } else {
            SQLRowStream wrapped = new RowStreamWrapper(conn, query.result());