Google Cloud Spanner C++ Client  2.2.1
A C++ Client Library for Google Cloud Spanner
row.h
Go to the documentation of this file.
1 // Copyright 2022 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_MOCKS_ROW_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_MOCKS_ROW_H
17 
18 #include "google/cloud/spanner/row.h"
19 #include "google/cloud/spanner/value.h"
20 #include "google/cloud/version.h"
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 namespace google {
26 namespace cloud {
27 namespace spanner_mocks {
29 
30 // TODO(#9086): Delete this when the MakeRow() implementation is moved here.
31 #include "google/cloud/internal/disable_deprecation_warnings.inc"
32 
33 /**
34  * Creates a `spanner::Row` with the specified column names and values.
35  *
36  * This overload accepts a vector of pairs, allowing the caller to specify both
37  * the column names and the `spanner::Value` that goes in each column.
38  *
39  * This function is intended for application developers who are mocking the
40  * results of a `Client::ExecuteQuery` call.
41  */
43  std::vector<std::pair<std::string, spanner::Value>> pairs) {
44  return spanner::MakeTestRow(std::move(pairs));
45 }
46 
47 /**
48  * Creates a `spanner::Row` with `spanner::Value`s created from the given
49  * arguments and with auto-generated column names.
50  *
51  * This overload accepts a variadic list of arguments that will be used to
52  * create the `spanner::Value`s in the row. The column names will be implicitly
53  * generated, the first column being "0", the second "1", and so on,
54  * corresponding to the argument's position.
55  *
56  * This function is intended for application developers who are mocking the
57  * results of a `Client::ExecuteQuery` call.
58  */
59 template <typename... Ts>
60 spanner::Row MakeRow(Ts&&... ts) {
61  return spanner::MakeTestRow(std::forward<Ts>(ts)...);
62 }
63 
64 // TODO(#9086): Delete this when the MakeRow() implementation is moved here.
65 #include "google/cloud/internal/diagnostics_pop.inc"
66 
68 } // namespace spanner_mocks
69 } // namespace cloud
70 } // namespace google
71 
72 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_MOCKS_ROW_H