Skip to content

Commit

Permalink
Add lvalue reference queryWithGenerator APIs
Browse files Browse the repository at this point in the history
Summary: TSIA. This makes the migration a bit easy with no additional cost except some code. Example next diff: D66009586

Differential Revision: D66119825

fbshipit-source-id: cffe2810cf74c9a4f99fc90c3bedaccf96afb0d6
  • Loading branch information
Sai Nagabhairava authored and facebook-github-bot committed Nov 19, 2024
1 parent 5236099 commit 5c823dd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
40 changes: 40 additions & 0 deletions third-party/squangle/src/squangle/mysql_client/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ DbQueryResult Connection::internalQueryWithGenerator(
query_generator.query(), std::move(cb), std::move(options));
}

DbQueryResult Connection::internalQueryWithGenerator(
QueryGenerator& query_generator,
QueryCallback&& cb,
QueryOptions&& options) {
facebook::common::mysql_client::sql_builder::OdsCounterHelper::
bumpOdsOverallCounter();
return Connection::query(
query_generator.query(), std::move(cb), std::move(options));
}

template <>
DbQueryResult Connection::queryWithGenerator(
QueryGenerator&& query_generator,
Expand All @@ -349,6 +359,15 @@ DbQueryResult Connection::queryWithGenerator(
std::move(query_generator), std::move(cb), std::move(options));
}

template <>
DbQueryResult Connection::queryWithGenerator(
QueryGenerator& query_generator,
QueryCallback&& cb,
QueryOptions&& options) {
return internalQueryWithGenerator(
query_generator, std::move(cb), std::move(options));
}

template <>
DbQueryResult Connection::queryWithGenerator(
QueryGenerator&& query_generator,
Expand All @@ -357,12 +376,25 @@ DbQueryResult Connection::queryWithGenerator(
std::move(query_generator), (QueryCallback) nullptr, std::move(options));
}

template <>
DbQueryResult Connection::queryWithGenerator(
QueryGenerator& query_generator,
QueryOptions&& options) {
return Connection::queryWithGenerator(
query_generator, (QueryCallback) nullptr, std::move(options));
}

template <>
DbQueryResult Connection::queryWithGenerator(QueryGenerator&& query_generator) {
return Connection::queryWithGenerator(
std::move(query_generator), QueryOptions());
}

template <>
DbQueryResult Connection::queryWithGenerator(QueryGenerator& query_generator) {
return Connection::queryWithGenerator(query_generator, QueryOptions());
}

template <>
DbQueryResult Connection::queryWithGenerator(
QueryGenerator&& query_generator,
Expand All @@ -371,6 +403,14 @@ DbQueryResult Connection::queryWithGenerator(
std::move(query_generator), std::move(cb), QueryOptions());
}

template <>
DbQueryResult Connection::queryWithGenerator(
QueryGenerator& query_generator,
QueryCallback&& cb) {
return Connection::queryWithGenerator(
query_generator, std::move(cb), QueryOptions());
}

// MultiQuery

DbMultiQueryResult Connection::internalMultiQuery(
Expand Down
22 changes: 21 additions & 1 deletion third-party/squangle/src/squangle/mysql_client/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ class Connection {
QueryGenerator&& query_generator,
Args&&... args);

template <typename... Args>
DbQueryResult queryWithGenerator(
QueryGenerator& query_generator,
Args&&... args);

template <>
DbQueryResult queryWithGenerator(
QueryGenerator& query_generator,
QueryCallback&& cb,
QueryOptions&& options);

template <typename... Args>
DbMultiQueryResult multiQueryWithGenerators(
std::vector<std::unique_ptr<QueryGenerator>>&& query_generators,
Expand Down Expand Up @@ -648,12 +659,21 @@ class Connection {
// QueryWithGenerator

// This method holds the core logic for queryWithGenerator and can be
// overridden in derived class
// overridden in derived class. QueryGenerator is passed as an rvalue
// reference
virtual DbQueryResult internalQueryWithGenerator(
QueryGenerator&& query_Generator,
QueryCallback&& cb,
QueryOptions&& options);

// This method holds the core logic for queryWithGenerator and can be
// overridden in derived class. QueryGenerator is passed as an lvalue
// reference
virtual DbQueryResult internalQueryWithGenerator(
QueryGenerator& query_Generator,
QueryCallback&& cb,
QueryOptions&& options);

// MultiQueryWithGenerator

// This method holds the core logic for multiQueryWithGenerator and can be
Expand Down

0 comments on commit 5c823dd

Please sign in to comment.