Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
row.h
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
25namespace google {
26namespace cloud {
27namespace spanner_mocks {
28GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
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 */
42inline spanner::Row MakeRow(
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 */
59template <typename... Ts>
60spanner::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
67GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
68} // namespace spanner_mocks
69} // namespace cloud
70} // namespace google
71
72#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_MOCKS_ROW_H
A Row is a sequence of columns each with a name and an associated Value.
Definition: row.h:84
The Value class represents a type-safe, nullable Spanner value.
Definition: value.h:170
Define classes to mock the Cloud Spanner C++ client APIs.
Definition: mock_database_admin_connection.h:24
spanner::Row MakeRow(std::vector< std::pair< std::string, spanner::Value > > pairs)
Creates a spanner::Row with the specified column names and values.
Definition: row.h:42
spanner::Row MakeRow(Ts &&... ts)
Creates a spanner::Row with spanner::Values created from the given arguments and with auto-generated ...
Definition: row.h:60
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
Row MakeTestRow(std::vector< std::pair< std::string, Value > > pairs)
Creates a Row with the specified column names and values.