DbQueryResult Connection::query()

in squangle/mysql_client/Connection.cpp [258:301]


DbQueryResult Connection::query(Query&& query, QueryOptions&& options) {
  auto op = beginAnyQuery<QueryOperation>(
      Operation::ConnectionProxy(Operation::ReferencedConnection(this)),
      std::move(query));
  op->setAttributes(std::move(options.getAttributes()));
  SCOPE_EXIT {
    operation_in_progress_ = false;
  };
  operation_in_progress_ = true;

  if (op->callbacks_.pre_query_callback_) {
    op->callbacks_.pre_query_callback_(*op).get();
  }
  op->run()->wait();

  if (!op->ok()) {
    throw QueryException(
        op->numQueriesExecuted(),
        op->result(),
        op->mysql_errno(),
        op->mysql_error(),
        *getKey(),
        op->elapsed());
  }
  auto conn_key = *op->connection()->getKey();
  DbQueryResult result(
      std::move(op->stealQueryResult()),
      op->numQueriesExecuted(),
      op->resultSize(),
      nullptr,
      op->result(),
      conn_key,
      op->elapsed());
  if (op->callbacks_.post_query_callback_) {
    // If we have a callback set, wrap (and then unwrap) the result to/from the
    // callback's std::variant wrapper
    return op->callbacks_.post_query_callback_(std::move(result))
        .deferValue([](AsyncPostQueryResult&& result) {
          return std::get<DbQueryResult>(std::move(result));
        })
        .get();
  }
  return result;
}