Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
client.h
1// Copyright 2019 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_CLIENT_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CLIENT_H
17
18#include "google/cloud/spanner/batch_dml_result.h"
19#include "google/cloud/spanner/client_options.h"
20#include "google/cloud/spanner/commit_options.h"
21#include "google/cloud/spanner/commit_result.h"
22#include "google/cloud/spanner/connection.h"
23#include "google/cloud/spanner/connection_options.h"
24#include "google/cloud/spanner/database.h"
25#include "google/cloud/spanner/internal/defaults.h"
26#include "google/cloud/spanner/keys.h"
27#include "google/cloud/spanner/mutations.h"
28#include "google/cloud/spanner/partition_options.h"
29#include "google/cloud/spanner/query_options.h"
30#include "google/cloud/spanner/query_partition.h"
31#include "google/cloud/spanner/read_options.h"
32#include "google/cloud/spanner/read_partition.h"
33#include "google/cloud/spanner/results.h"
34#include "google/cloud/spanner/retry_policy.h"
35#include "google/cloud/spanner/session_pool_options.h"
36#include "google/cloud/spanner/sql_statement.h"
37#include "google/cloud/spanner/transaction.h"
38#include "google/cloud/spanner/version.h"
39#include "google/cloud/backoff_policy.h"
40#include "google/cloud/internal/non_constructible.h"
41#include "google/cloud/options.h"
42#include "google/cloud/status.h"
43#include "google/cloud/status_or.h"
44#include <google/spanner/v1/spanner.pb.h>
45#include <grpcpp/grpcpp.h>
46#include <functional>
47#include <initializer_list>
48#include <memory>
49#include <string>
50#include <vector>
51
52namespace google {
53namespace cloud {
54namespace spanner {
55GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
56
57// clang-format off
58/**
59 * Performs database client operations on Spanner.
60 *
61 * Applications use this class to perform operations on
62 * [Spanner Databases][spanner-doc-link].
63 *
64 * @par Performance
65 *
66 * `Client` objects are relatively cheap to create, copy, and move. However,
67 * each `Client` object must be created with a `std::shared_ptr<Connection>`,
68 * which itself is relatively expensive to create. Therefore, connection
69 * instances should be shared when possible. See the `MakeConnection()` method
70 * and the `Connection` interface for more details.
71 *
72 * @par Thread Safety
73 *
74 * Instances of this class created via copy-construction or copy-assignment
75 * share the underlying pool of connections. Access to these copies via multiple
76 * threads is guaranteed to work. Two threads operating on the same instance of
77 * this class is not guaranteed to work.
78 *
79 * @par Error Handling
80 *
81 * This class uses `StatusOr<T>` to report errors. When an operation fails to
82 * perform its work the returned `StatusOr<T>` contains the error details. If
83 * the `ok()` member function in the `StatusOr<T>` returns `true` then it
84 * contains the expected result. For more information, see the
85 * [Error Handling Guide](#spanner-error-handling).
86 *
87 * @code
88 * namespace spanner = ::google::cloud::spanner;
89 *
90 * auto db = spanner::Database("my_project", "my_instance", "my_db_id"));
91 * auto conn = spanner::MakeConnection(db);
92 * auto client = spanner::Client(conn);
93 *
94 * auto rows = client.Read(...);
95 * using RowType = std::tuple<std::int64_t, std::string>;
96 * for (auto const& row : spanner::StreamOf<RowType>(rows)) {
97 * // ...
98 * }
99 * @endcode
100 *
101 * @par Query Options
102 *
103 * Most operations that take an `SqlStatement` may also be modified with
104 * query `Options`. These options can be set at various levels, with more
105 * specific levels taking precedence over broader ones. For example,
106 * `Options` that are passed directly to `Client::ExecuteQuery()` will
107 * take precedence over the `Client`-level defaults (if any), which will
108 * themselves take precedence over any environment variables. The following
109 * table shows the environment variables that may optionally be set and the
110 * query `Options` setting that they affect.
111 *
112 * Environment Variable | Options setting
113 * -------------------------------------- | --------------------
114 * `SPANNER_OPTIMIZER_VERSION` | `QueryOptimizerVersionOption`
115 * `SPANNER_OPTIMIZER_STATISTICS_PACKAGE` | `QueryOptimizerStatisticsPackageOption`
116 *
117 * @see https://cloud.google.com/spanner/docs/reference/rest/v1/QueryOptions
118 * @see http://cloud/spanner/docs/query-optimizer/manage-query-optimizer
119 *
120 * [spanner-doc-link]:
121 * https://cloud.google.com/spanner/docs/api-libraries-overview
122 */
123// clang-format on
124class Client {
125 public:
126 /**
127 * Constructs a `Client` object using the specified @p conn and @p opts.
128 *
129 * See `MakeConnection()` for how to create a connection to Spanner. To help
130 * with unit testing, callers may create fake/mock `Connection` objects that
131 * are injected into the `Client`.
132 */
133 explicit Client(std::shared_ptr<Connection> conn, Options opts = {})
134 : conn_(std::move(conn)),
135 opts_(internal::MergeOptions(std::move(opts), conn_->options())) {}
136
137 /// No default construction.
138 Client() = delete;
139
140 ///@{
141 /// @name Copy and move support
142 Client(Client const&) = default;
143 Client& operator=(Client const&) = default;
144 Client(Client&&) = default;
145 Client& operator=(Client&&) = default;
146 ///@}
147
148 ///@{
149 /// @name Equality
150 friend bool operator==(Client const& a, Client const& b) {
151 return a.conn_ == b.conn_;
152 }
153 friend bool operator!=(Client const& a, Client const& b) { return !(a == b); }
154 ///@}
155
156 /**
157 * Reads rows from the database using key lookups and scans, as a simple
158 * key/value style alternative to `ExecuteQuery()`.
159 *
160 * Callers can optionally supply a `Transaction` or
161 * `Transaction::SingleUseOptions` used to create a single-use transaction -
162 * or neither, in which case a single-use transaction with default options
163 * is used.
164 *
165 * @note No individual row in the `ReadResult` can exceed 100 MiB, and no
166 * column value can exceed 10 MiB.
167 *
168 * @par Example
169 * @snippet samples.cc read-data
170 *
171 * @param table The name of the table in the database to be read.
172 * @param keys Identifies the rows to be yielded. If `read_options.index_name`
173 * is set, names keys in that index; otherwise names keys in the primary
174 * index of `table`. It is not an error for `keys` to name rows that do
175 * not exist in the database; `Read` yields nothing for nonexistent rows.
176 * @param columns The columns of `table` to be returned for each row matching
177 * this request.
178 * @param opts `Options` used for this request.
179 */
180 RowStream Read(std::string table, KeySet keys,
181 std::vector<std::string> columns, Options opts = {});
182
183 /**
184 * @copydoc Read
185 *
186 * @param transaction_options Execute this read in a single-use transaction
187 * with these options.
188 */
189 RowStream Read(Transaction::SingleUseOptions transaction_options,
190 std::string table, KeySet keys,
191 std::vector<std::string> columns, Options opts = {});
192
193 /**
194 * @copydoc Read
195 *
196 * @param transaction Execute this read as part of an existing transaction.
197 */
198 RowStream Read(Transaction transaction, std::string table, KeySet keys,
199 std::vector<std::string> columns, Options opts = {});
200
201 /**
202 * Reads rows from a subset of rows in a database. Requires a prior call
203 * to `PartitionRead` to obtain the partition information; see the
204 * documentation of that method for full details.
205 * @note No individual row in the `ReadResult` can exceed 100 MiB, and no
206 * column value can exceed 10 MiB.
207 *
208 * @par Example
209 * @snippet samples.cc read-read-partition
210 *
211 * @param partition A `ReadPartition`, obtained by calling `PartitionRead`.
212 * @param opts `Options` used for this request.
213 */
214 RowStream Read(ReadPartition const& partition, Options opts = {});
215
216 /**
217 * Creates a set of partitions that can be used to execute a read
218 * operation in parallel. Each of the returned partitions can be passed
219 * to `Read` to specify a subset of the read result to read.
220 *
221 * There are no ordering guarantees on rows returned among the returned
222 * partition, or even within each individual `Read` call issued with a given
223 * partition.
224 *
225 * Partitions become invalid when the session used to create them is deleted,
226 * is idle for too long, begins a new transaction, or becomes too old. When
227 * any of these happen, it is not possible to resume the read, and the whole
228 * operation must be restarted from the beginning.
229 *
230 * @par Example
231 * @snippet samples.cc partition-read
232 *
233 * @param transaction The transaction to execute the operation in.
234 * **Must** be a read-only snapshot transaction.
235 * @param table The name of the table in the database to be read.
236 * @param keys Identifies the rows to be yielded. If `read_options.index_name`
237 * is set, names keys in that index; otherwise names keys in the primary
238 * index of `table`. It is not an error for `keys` to name rows that do
239 * not exist in the database; `Read` yields nothing for nonexistent rows.
240 * @param columns The columns of `table` to be returned for each row matching
241 * this request.
242 * @param opts `Options` used for this request.
243 *
244 * @return A `StatusOr` containing a vector of `ReadPartition` or error
245 * status on failure.
246 */
247 StatusOr<std::vector<ReadPartition>> PartitionRead(
248 Transaction transaction, std::string table, KeySet keys,
249 std::vector<std::string> columns, Options opts = {});
250
251 /**
252 * Executes a SQL query.
253 *
254 * Operations inside read-write transactions might return `ABORTED`. If this
255 * occurs, the application should restart the transaction from the beginning.
256 *
257 * Callers can optionally supply a `Transaction` or
258 * `Transaction::SingleUseOptions` used to create a single-use transaction -
259 * or neither, in which case a single-use transaction with default options
260 * is used.
261 *
262 * `SELECT * ...` queries are supported, but there's no guarantee about the
263 * order, nor number, of returned columns. Therefore, the caller must look up
264 * the wanted values in each row by column name. When the desired column
265 * names are known in advance, it is better to list them explicitly in the
266 * query's SELECT statement, so that unnecessary values are not
267 * returned/ignored, and the column order is known. This enables more
268 * efficient and simpler code.
269 *
270 * Can also execute a DML statement with a returning clause in a read/write
271 * transaction.
272 *
273 * @note No individual row in the `RowStream` can exceed 100 MiB, and no
274 * column value can exceed 10 MiB.
275 *
276 * @par Example
277 * Query with explicitly selected columns.
278 * @snippet samples.cc spanner-query-data
279 *
280 * @par Example
281 * Using `SELECT *`.
282 * @snippet samples.cc spanner-query-data-select-star
283 *
284 * @par Example
285 * Using a DML statement with `THEN RETURN`.
286 * @snippet samples.cc spanner-update-dml-returning
287 *
288 * @param statement The SQL statement to execute.
289 * @param opts (optional) The `Options` to use for this call. If given,
290 * these will take precedence over the options set at the client and
291 * environment levels.
292 */
294
295 /**
296 * @copydoc ExecuteQuery(SqlStatement, Options)
297 *
298 * @param transaction_options Execute this query in a single-use transaction
299 * with these options.
300 */
302 SqlStatement statement, Options opts = {});
303
304 /**
305 * @copydoc ExecuteQuery(SqlStatement, Options)
306 *
307 * @param transaction Execute this query as part of an existing transaction.
308 */
309 RowStream ExecuteQuery(Transaction transaction, SqlStatement statement,
310 Options opts = {});
311
312 /**
313 * Executes a SQL query on a subset of rows in a database. Requires a prior
314 * call to `PartitionQuery` to obtain the partition information; see the
315 * documentation of that method for full details.
316 *
317 * @note No individual row in the `RowStream` can exceed 100 MiB, and no
318 * column value can exceed 10 MiB.
319 *
320 * @par Example
321 * @snippet samples.cc execute-sql-query-partition
322 *
323 * @param partition A `QueryPartition`, obtained by calling `PartitionQuery`.
324 * @param opts (optional) The `Options` to use for this call. If given,
325 * these will take precedence over the options set at the client and
326 * environment levels.
327 */
328 RowStream ExecuteQuery(QueryPartition const& partition, Options opts = {});
329
330 /**
331 * Profiles a SQL query.
332 *
333 * Profiling executes the query, provides the resulting rows, `ExecutionPlan`,
334 * and execution statistics.
335 *
336 * Operations inside read-write transactions might return `kAborted`. If this
337 * occurs, the application should restart the transaction from the beginning.
338 *
339 * Callers can optionally supply a `Transaction` or
340 * `Transaction::SingleUseOptions` used to create a single-use transaction -
341 * or neither, in which case a single-use transaction with default options
342 * is used.
343 *
344 * @note Callers must consume all rows from the result before execution
345 * statistics and `ExecutionPlan` are available.
346 *
347 * @note No individual row in the `ProfileQueryResult` can exceed 100 MiB, and
348 * no column value can exceed 10 MiB.
349 *
350 * @par Example
351 * @snippet samples.cc profile-query
352 *
353 * @param statement The SQL statement to execute.
354 * @param opts (optional) The `Options` to use for this call. If given,
355 * these will take precedence over the options set at the client and
356 * environment levels.
357 *
358 */
360
361 /**
362 * @copydoc ProfileQuery(SqlStatement, Options)
363 *
364 * @param transaction_options Execute this query in a single-use transaction
365 * with these options.
366 */
368 Transaction::SingleUseOptions transaction_options, SqlStatement statement,
369 Options opts = {});
370
371 /**
372 * @copydoc ProfileQuery(SqlStatement, Options)
373 *
374 * @param transaction Execute this query as part of an existing transaction.
375 */
377 SqlStatement statement, Options opts = {});
378
379 /**
380 * Creates a set of partitions that can be used to execute a query
381 * operation in parallel. Each of the returned partitions can be passed
382 * to `ExecuteQuery` to specify a subset of the query result to read.
383 *
384 * Partitions become invalid when the session used to create them is deleted,
385 * is idle for too long, begins a new transaction, or becomes too old. When
386 * any of these happen, it is not possible to resume the query, and the whole
387 * operation must be restarted from the beginning.
388 *
389 * @par Example
390 * @snippet samples.cc partition-query
391 *
392 * @param transaction The transaction to execute the operation in.
393 * **Must** be a read-only snapshot transaction.
394 * @param statement The SQL statement to execute.
395 * @param opts `Options` used for this request.
396 *
397 * @return A `StatusOr` containing a vector of `QueryPartition`s or error
398 * status on failure.
399 */
400 StatusOr<std::vector<QueryPartition>> PartitionQuery(
401 Transaction transaction, SqlStatement statement,
402 Options opts = Options{});
403
404 /**
405 * Executes a SQL DML statement.
406 *
407 * Operations inside read-write transactions might return `ABORTED`. If this
408 * occurs, the application should restart the transaction from the beginning.
409 *
410 * @note Single-use transactions are not supported with DML statements.
411 *
412 * @par Example
413 * @snippet samples.cc execute-dml
414 *
415 * @param transaction Execute this query as part of an existing transaction.
416 * @param statement The SQL statement to execute.
417 * @param opts (optional) The `Options` to use for this call. If given,
418 * these will take precedence over the options set at the client and
419 * environment levels.
420 */
421 StatusOr<DmlResult> ExecuteDml(Transaction transaction,
422 SqlStatement statement, Options opts = {});
423
424 /**
425 * Profiles a SQL DML statement.
426 *
427 * Profiling executes the DML statement, provides the modified row count,
428 * `ExecutionPlan`, and execution statistics.
429 *
430 * Operations inside read-write transactions might return `ABORTED`. If this
431 * occurs, the application should restart the transaction from the beginning.
432 *
433 * @note Single-use transactions are not supported with DML statements.
434 *
435 * @par Example
436 * @snippet samples.cc profile-dml
437 *
438 * @param transaction Execute this query as part of an existing transaction.
439 * @param statement The SQL statement to execute.
440 * @param opts (optional) The `Options` to use for this call. If given,
441 * these will take precedence over the options set at the client and
442 * environment levels.
443 */
444 StatusOr<ProfileDmlResult> ProfileDml(Transaction transaction,
445 SqlStatement statement,
446 Options opts = {});
447
448 /**
449 * Analyzes the execution plan of a SQL statement.
450 *
451 * Analyzing provides the `ExecutionPlan`, but does not execute the SQL
452 * statement.
453 *
454 * Operations inside read-write transactions might return `ABORTED`. If this
455 * occurs, the application should restart the transaction from the beginning.
456 *
457 * @note Single-use transactions are not supported with DML statements.
458 *
459 * @par Example
460 * @snippet samples.cc analyze-query
461 *
462 * @param transaction Execute this query as part of an existing transaction.
463 * @param statement The SQL statement to execute.
464 * @param opts (optional) The `Options` to use for this call. If given,
465 * these will take precedence over the options set at the client and
466 * environment levels.
467 */
468 StatusOr<ExecutionPlan> AnalyzeSql(Transaction transaction,
469 SqlStatement statement, Options opts = {});
470
471 /**
472 * Executes a batch of SQL DML statements. This method allows many statements
473 * to be run with lower latency than submitting them sequentially with
474 * `ExecuteDml`.
475 *
476 * Statements are executed in order, sequentially. Execution will stop at the
477 * first failed statement; the remaining statements will not run.
478 *
479 * As with all read-write transactions, the results will not be visible
480 * outside of the transaction until it is committed. For that reason, it is
481 * advisable to run this method from a `Commit` mutator.
482 *
483 * @warning A returned status of OK from this function does not imply that
484 * all the statements were executed successfully. For that, you need to
485 * inspect the `BatchDmlResult::status` field.
486 *
487 * @par Example
488 * @snippet samples.cc execute-batch-dml
489 *
490 * @param transaction The read-write transaction to execute the operation in.
491 * @param statements The list of statements to execute in this batch.
492 * Statements are executed serially, such that the effects of statement i
493 * are visible to statement i+1. Each statement must be a DML statement.
494 * Execution will stop at the first failed statement; the remaining
495 * statements will not run. Must not be empty.
496 * @param opts (optional) The options to use for this call. Expected options
497 * are any of the types in the following option lists.
498 * - `google::cloud::RequestOptionList`
499 */
500 StatusOr<BatchDmlResult> ExecuteBatchDml(Transaction transaction,
501 std::vector<SqlStatement> statements,
502 Options opts = {});
503
504 /**
505 * Commits a read-write transaction.
506 *
507 * Calls the @p mutator in the context of a new read-write transaction.
508 * The @p mutator can execute read/write operations using the transaction,
509 * and returns any additional `Mutations` to commit.
510 *
511 * If the @p mutator succeeds and the transaction commits, then `Commit()`
512 * returns the `CommitResult`.
513 *
514 * If the @p mutator returns a non-rerunnable status (according to the
515 * @p rerun_policy), the transaction is rolled back and that status is
516 * returned. Similarly, if the transaction fails to commit with a non-
517 * rerunnable status, that status is returned.
518 *
519 * Otherwise the whole process repeats (subject to @p rerun_policy and
520 * @p backoff_policy), by building a new transaction and re-running the
521 * @p mutator. The lock priority of the operation increases after each
522 * rerun, meaning that the next attempt has a slightly better chance of
523 * success.
524 *
525 * Note that the @p mutator should only return a rerunnable status when
526 * the transaction is no longer usable (e.g., it was aborted). Otherwise
527 * the transaction will be leaked.
528 *
529 * @par Example
530 * @snippet samples.cc commit-with-policies
531 *
532 * @param mutator the function called to create mutations
533 * @param rerun_policy controls for how long (or how many times) the mutator
534 * will be rerun after the transaction aborts.
535 * @param backoff_policy controls how long `Commit` waits between reruns.
536 * @param opts (optional) The options to use for this call. Expected options
537 * include any of the following types:
538 * - `google::cloud::spanner::CommitReturnStatsOption`
539 * - `google::cloud::spanner::RequestPriorityOption`
540 * - `google::cloud::spanner::TransactionTagOption`
541 *
542 * @throw Rethrows any exception thrown by @p `mutator` (after rolling back
543 * the transaction). However, a `RuntimeStatusError` exception is
544 * instead consumed and converted into a `mutator` return value of the
545 * enclosed `Status`.
546 */
547 StatusOr<CommitResult> Commit(
548 std::function<StatusOr<Mutations>(Transaction)> const& mutator,
549 std::unique_ptr<TransactionRerunPolicy> rerun_policy,
550 std::unique_ptr<BackoffPolicy> backoff_policy, Options opts = {});
551
552 /**
553 * Commits a read-write transaction.
554 *
555 * Same as above, but uses the default rerun and backoff policies.
556 *
557 * @par Example
558 * @snippet samples.cc commit-with-mutator
559 *
560 * @param mutator the function called to create mutations
561 * @param opts (optional) The options to use for this call.
562 */
563 StatusOr<CommitResult> Commit(
564 std::function<StatusOr<Mutations>(Transaction)> const& mutator,
565 Options opts = {});
566
567 /**
568 * Commits the @p mutations, using the @p options, atomically in order.
569 *
570 * @par Example
571 * @snippet samples.cc commit-with-mutations
572 *
573 * This function uses the re-run loop described above with the default
574 * policies.
575 */
576 StatusOr<CommitResult> Commit(Mutations mutations, Options opts = {});
577
578 /**
579 * Commits a read-write transaction.
580 *
581 * The commit might return a `kAborted` error. This can occur at any time.
582 * Commonly the cause is conflicts with concurrent transactions, however
583 * it can also happen for a variety of other reasons. If `Commit` returns
584 * `kAborted`, the caller may try to reapply the mutations within a new
585 * read-write transaction (which should share lock priority with the aborted
586 * transaction so that the new attempt has a slightly better chance of
587 * success).
588 *
589 * @warning It is an error to call `Commit` with a read-only transaction.
590 *
591 * @note Prefer the previous `Commit` overloads if you want to simply reapply
592 * mutations after a `kAborted` error.
593 *
594 * @param transaction The transaction to commit.
595 * @param mutations The mutations to be executed when this transaction
596 * commits. All mutations are applied atomically, in the order they
597 * appear in this list.
598 * @param opts (optional) The options to use for this call.
599 *
600 * @return A `StatusOr` containing the result of the commit or error status
601 * on failure.
602 */
603 StatusOr<CommitResult> Commit(Transaction transaction, Mutations mutations,
604 Options opts = {});
605
606 /**
607 * Commits a write transaction with at-least-once semantics.
608 *
609 * Apply the given mutations atomically, using a single RPC, and therefore
610 * without replay protection. That is, it is possible that the mutations
611 * will be applied more than once. If the mutations are not idempotent, this
612 * may lead to a failure (for example, an insert may fail with "already
613 * exists" even though the row did not exist before the call was made).
614 * Accordingly, this call may only be appropriate for idempotent, latency-
615 * sensitive and/or high-throughput blind writing.
616 *
617 * @note Prefer the `Commit` overloads if you want exactly-once semantics
618 * or want to reapply mutations after a `kAborted` error.
619 *
620 * @par Example
621 * @snippet samples.cc commit-at-least-once
622 *
623 * @param transaction_options Execute the commit in a temporary transaction
624 * with these options.
625 * @param mutations The mutations to be executed when this transaction
626 * commits. All mutations are applied atomically, in the order they
627 * appear in this list.
628 * @param opts (optional) The options to use for this call.
629 *
630 * @return A `StatusOr` containing the result of the commit or error status
631 * on failure.
632 */
634 Transaction::ReadWriteOptions transaction_options, Mutations mutations,
635 Options opts = {});
636
637 /**
638 * Rolls back a read-write transaction, releasing any locks it holds.
639 *
640 * At any time before `Commit`, the client can call `Rollback` to abort the
641 * transaction. It is a good idea to call this for any read-write transaction
642 * that includes one or more `Read`, `ExecuteQuery`, or `ExecuteDml` requests
643 * and ultimately decides not to commit.
644 *
645 * @warning It is an error to call `Rollback` with a read-only transaction.
646 *
647 * @param transaction The transaction to roll back.
648 * @param opts (optional) The options to use for this call.
649 *
650 * @return The error status of the rollback.
651 */
652 Status Rollback(Transaction transaction, Options opts = {});
653
654 /**
655 * Executes a Partitioned DML SQL query.
656 *
657 * @par Example
658 * @snippet samples.cc execute-sql-partitioned
659 *
660 * @param statement the SQL statement to execute. Please see the
661 * [spanner documentation][dml-partitioned] for the restrictions on the
662 * SQL statements supported by this function.
663 * @param opts (optional) The `Options` to use for this call. If given,
664 * these will take precedence over the options set at the client and
665 * environment levels.
666 *
667 * @see [Partitioned DML Transactions][txn-partitioned] for an overview of
668 * Partitioned DML transactions.
669 * @see [Partitioned DML][dml-partitioned] for a description of which SQL
670 * statements are supported in Partitioned DML transactions.
671 * [txn-partitioned]:
672 * https://cloud.google.com/spanner/docs/transactions#partitioned_dml_transactions
673 * [dml-partitioned]: https://cloud.google.com/spanner/docs/dml-partitioned
674 */
676 Options opts = {});
677
678 ///@{
679 /// @name Backwards compatibility for ClientOptions.
680 explicit Client(std::shared_ptr<Connection> conn, ClientOptions const& opts)
681 : Client(std::move(conn), Options(opts)) {}
682 explicit Client(std::shared_ptr<Connection> conn,
683 std::initializer_list<internal::NonConstructible>)
684 : Client(std::move(conn)) {}
685 ///@}
686
687 ///@{
688 /// @name Backwards compatibility for ReadOptions.
689 /**
690 * @copybrief Read(std::string,KeySet,std::vector<std::string>,Options)
691 * @see Read(std::string,KeySet,std::vector<std::string>,Options)
692 */
693 RowStream Read(std::string table, KeySet keys,
694 std::vector<std::string> columns,
695 ReadOptions const& read_options) {
696 return Read(std::move(table), std::move(keys), std::move(columns),
697 ToOptions(read_options));
698 }
699 /**
700 * @copybrief Read(std::string,KeySet,std::vector<std::string>,Options)
701 * @see Read(std::string,KeySet,std::vector<std::string>,Options)
702 */
703 RowStream Read(std::string table, KeySet keys,
704 std::vector<std::string> columns,
705 std::initializer_list<internal::NonConstructible>) {
706 return Read(std::move(table), std::move(keys), std::move(columns));
707 }
708 /**
709 * @copybrief Read(Transaction::SingleUseOptions,std::string,KeySet,std::vector<std::string>,Options)
710 * @see Read(Transaction::SingleUseOptions,std::string,KeySet,std::vector<std::string>,Options)
711 */
712 RowStream Read(Transaction::SingleUseOptions transaction_options,
713 std::string table, KeySet keys,
714 std::vector<std::string> columns,
715 ReadOptions const& read_options) {
716 return Read(std::move(transaction_options), std::move(table),
717 std::move(keys), std::move(columns), ToOptions(read_options));
718 }
719 /**
720 * @copybrief Read(Transaction::SingleUseOptions,std::string,KeySet,std::vector<std::string>,Options)
721 * @see Read(Transaction::SingleUseOptions,std::string,KeySet,std::vector<std::string>,Options)
722 */
723 RowStream Read(Transaction::SingleUseOptions transaction_options,
724 std::string table, KeySet keys,
725 std::vector<std::string> columns,
726 std::initializer_list<internal::NonConstructible>) {
727 return Read(std::move(transaction_options), std::move(table),
728 std::move(keys), std::move(columns));
729 }
730 /**
731 * @copybrief Read(Transaction,std::string,KeySet,std::vector<std::string>,Options)
732 * @see Read(Transaction,std::string,KeySet,std::vector<std::string>,Options)
733 */
734 RowStream Read(Transaction transaction, std::string table, KeySet keys,
735 std::vector<std::string> columns,
736 ReadOptions const& read_options) {
737 return Read(std::move(transaction), std::move(table), std::move(keys),
738 std::move(columns), ToOptions(read_options));
739 }
740 /**
741 * @copybrief Read(Transaction,std::string,KeySet,std::vector<std::string>,Options)
742 * @see Read(Transaction,std::string,KeySet,std::vector<std::string>,Options)
743 */
744 RowStream Read(Transaction transaction, std::string table, KeySet keys,
745 std::vector<std::string> columns,
746 std::initializer_list<internal::NonConstructible>) {
747 return Read(std::move(transaction), std::move(table), std::move(keys),
748 std::move(columns));
749 }
750 ///@}
751
752 ///@{
753 /// @name Backwards compatibility for ReadOptions and PartitionOptions.
754 /**
755 * @copybrief PartitionRead(Transaction,std::string,KeySet,std::vector<std::string>,Options)
756 * @see PartitionRead(Transaction,std::string,KeySet,std::vector<std::string>,Options)
757 */
758 StatusOr<std::vector<ReadPartition>> PartitionRead(
759 Transaction transaction, std::string table, KeySet keys,
760 std::vector<std::string> columns, ReadOptions const& read_options,
761 PartitionOptions const& partition_options) {
762 return PartitionRead(std::move(transaction), std::move(table),
763 std::move(keys), std::move(columns),
764 internal::MergeOptions(ToOptions(read_options),
765 ToOptions(partition_options)));
766 }
767 /**
768 * @copybrief PartitionRead(Transaction,std::string,KeySet,std::vector<std::string>,Options)
769 * @see PartitionRead(Transaction,std::string,KeySet,std::vector<std::string>,Options)
770 */
771 StatusOr<std::vector<ReadPartition>> PartitionRead(
772 Transaction transaction, std::string table, KeySet keys,
773 std::vector<std::string> columns,
774 std::initializer_list<internal::NonConstructible>) {
775 return PartitionRead(std::move(transaction), std::move(table),
776 std::move(keys), std::move(columns));
777 }
778 ///@}
779
780 ///@{
781 /// @name Backwards compatibility for QueryOptions.
782 /**
783 * @copybrief ExecuteQuery(SqlStatement,Options)
784 * @see ExecuteQuery(SqlStatement,Options)
785 */
786 RowStream ExecuteQuery(SqlStatement statement, QueryOptions const& opts) {
787 return ExecuteQuery(std::move(statement), Options(opts));
788 }
789 /**
790 * @copybrief ExecuteQuery(SqlStatement,Options)
791 * @see ExecuteQuery(SqlStatement,Options)
792 */
794 std::initializer_list<internal::NonConstructible>) {
795 return ExecuteQuery(std::move(statement));
796 }
797 /**
798 * @copybrief ExecuteQuery(Transaction::SingleUseOptions,SqlStatement,Options)
799 * @see ExecuteQuery(Transaction::SingleUseOptions,SqlStatement,Options)
800 */
802 SqlStatement statement, QueryOptions const& opts) {
803 return ExecuteQuery(std::move(transaction_options), std::move(statement),
804 Options(opts));
805 }
806 /**
807 * @copybrief ExecuteQuery(Transaction::SingleUseOptions,SqlStatement,Options)
808 * @see ExecuteQuery(Transaction::SingleUseOptions,SqlStatement,Options)
809 */
811 SqlStatement statement,
812 std::initializer_list<internal::NonConstructible>) {
813 return ExecuteQuery(std::move(transaction_options), std::move(statement));
814 }
815 /**
816 * @copybrief ExecuteQuery(Transaction,SqlStatement,Options)
817 * @see ExecuteQuery(Transaction,SqlStatement,Options)
818 */
819 RowStream ExecuteQuery(Transaction transaction, SqlStatement statement,
820 QueryOptions const& opts) {
821 return ExecuteQuery(std::move(transaction), std::move(statement),
822 Options(opts));
823 }
824 /**
825 * @copybrief ExecuteQuery(Transaction,SqlStatement,Options)
826 * @see ExecuteQuery(Transaction,SqlStatement,Options)
827 */
828 RowStream ExecuteQuery(Transaction transaction, SqlStatement statement,
829 std::initializer_list<internal::NonConstructible>) {
830 return ExecuteQuery(std::move(transaction), std::move(statement));
831 }
832 /**
833 * @copybrief ExecuteQuery(QueryPartition const&,Options)
834 * @see ExecuteQuery(QueryPartition const&,Options)
835 */
836 RowStream ExecuteQuery(QueryPartition const& partition,
837 QueryOptions const& opts) {
838 return ExecuteQuery(partition, Options(opts));
839 }
840 /**
841 * @copybrief ExecuteQuery(QueryPartition const&,Options)
842 * @see ExecuteQuery(QueryPartition const&,Options)
843 */
844 RowStream ExecuteQuery(QueryPartition const& partition,
845 std::initializer_list<internal::NonConstructible>) {
846 return ExecuteQuery(partition);
847 }
848 ///@}
849
850 ///@{
851 /// @name Backwards compatibility for QueryOptions.
852 /**
853 * @copybrief ProfileQuery(SqlStatement,Options)
854 * @see ProfileQuery(SqlStatement,Options)
855 */
857 QueryOptions const& opts) {
858 return ProfileQuery(std::move(statement), Options(opts));
859 }
860 /**
861 * @copybrief ProfileQuery(SqlStatement,Options)
862 * @see ProfileQuery(SqlStatement,Options)
863 */
865 SqlStatement statement,
866 std::initializer_list<internal::NonConstructible>) {
867 return ProfileQuery(std::move(statement));
868 }
869 /**
870 * @copybrief ProfileQuery(Transaction::SingleUseOptions,SqlStatement,Options)
871 * @see ProfileQuery(Transaction::SingleUseOptions,SqlStatement,Options)
872 */
874 Transaction::SingleUseOptions transaction_options, SqlStatement statement,
875 QueryOptions const& opts) {
876 return ProfileQuery(std::move(transaction_options), std::move(statement),
877 Options(opts));
878 }
879 /**
880 * @copybrief ProfileQuery(Transaction::SingleUseOptions,SqlStatement,Options)
881 * @see ProfileQuery(Transaction::SingleUseOptions,SqlStatement,Options)
882 */
884 Transaction::SingleUseOptions transaction_options, SqlStatement statement,
885 std::initializer_list<internal::NonConstructible>) {
886 return ProfileQuery(std::move(transaction_options), std::move(statement));
887 }
888 /**
889 * @copybrief ProfileQuery(Transaction,SqlStatement,Options)
890 * @see ProfileQuery(Transaction,SqlStatement,Options)
891 */
893 SqlStatement statement,
894 QueryOptions const& opts) {
895 return ProfileQuery(std::move(transaction), std::move(statement),
896 Options(opts));
897 }
898 /**
899 * @copybrief ProfileQuery(Transaction,SqlStatement,Options)
900 * @see ProfileQuery(Transaction,SqlStatement,Options)
901 */
903 Transaction transaction, SqlStatement statement,
904 std::initializer_list<internal::NonConstructible>) {
905 return ProfileQuery(std::move(transaction), std::move(statement));
906 }
907 ///@}
908
909 ///@{
910 /// @name Backwards compatibility for PartitionOptions.
911 /**
912 * @copybrief PartitionQuery(Transaction,SqlStatement,Options)
913 * @see PartitionQuery(Transaction,SqlStatement,Options)
914 */
915 StatusOr<std::vector<QueryPartition>> PartitionQuery(
916 Transaction transaction, SqlStatement statement,
917 PartitionOptions const& partition_options) {
918 return PartitionQuery(std::move(transaction), std::move(statement),
919 ToOptions(partition_options));
920 }
921 /**
922 * @copybrief PartitionQuery(Transaction,SqlStatement,Options)
923 * @see PartitionQuery(Transaction,SqlStatement,Options)
924 */
925 StatusOr<std::vector<QueryPartition>> PartitionQuery(
926 Transaction transaction, SqlStatement statement,
927 std::initializer_list<internal::NonConstructible>) {
928 return PartitionQuery(std::move(transaction), std::move(statement));
929 }
930 ///@}
931
932 ///@{
933 /// @name Backwards compatibility for QueryOptions.
934 /**
935 * @copybrief ExecuteDml(Transaction,SqlStatement,Options)
936 * @see ExecuteDml(Transaction,SqlStatement,Options)
937 */
938 StatusOr<DmlResult> ExecuteDml(Transaction transaction,
939 SqlStatement statement,
940 QueryOptions const& opts) {
941 return ExecuteDml(std::move(transaction), std::move(statement),
942 Options(opts));
943 }
944 /**
945 * @copybrief ExecuteDml(Transaction,SqlStatement,Options)
946 * @see ExecuteDml(Transaction,SqlStatement,Options)
947 */
948 StatusOr<DmlResult> ExecuteDml(
949 Transaction transaction, SqlStatement statement,
950 std::initializer_list<internal::NonConstructible>) {
951 return ExecuteDml(std::move(transaction), std::move(statement));
952 }
953 ///@}
954
955 ///@{
956 /// @name Backwards compatibility for QueryOptions.
957 StatusOr<ProfileDmlResult> ProfileDml(Transaction transaction,
958 SqlStatement statement,
959 QueryOptions const& opts) {
960 return ProfileDml(std::move(transaction), std::move(statement),
961 Options(opts));
962 }
964 Transaction transaction, SqlStatement statement,
965 std::initializer_list<internal::NonConstructible>) {
966 return ProfileDml(std::move(transaction), std::move(statement));
967 }
968 ///@}
969
970 ///@{
971 /// @name Backwards compatibility for QueryOptions.
972 /**
973 * @copybrief AnalyzeSql(Transaction,SqlStatement,Options)
974 * @see AnalyzeSql(Transaction,SqlStatement,Options)
975 */
976 StatusOr<ExecutionPlan> AnalyzeSql(Transaction transaction,
977 SqlStatement statement,
978 QueryOptions const& opts) {
979 return AnalyzeSql(std::move(transaction), std::move(statement),
980 Options(opts));
981 }
982 /**
983 * @copybrief AnalyzeSql(Transaction,SqlStatement,Options)
984 * @see AnalyzeSql(Transaction,SqlStatement,Options)
985 */
986 StatusOr<ExecutionPlan> AnalyzeSql(
987 Transaction transaction, SqlStatement statement,
988 std::initializer_list<internal::NonConstructible>) {
989 return AnalyzeSql(std::move(transaction), std::move(statement));
990 }
991 ///@}
992
993 ///@{
994 /// @name Backwards compatibility for CommitOptions.
995 /**
996 * @copybrief Commit(std::function<StatusOr<Mutations>(Transaction)> const&,std::unique_ptr<TransactionRerunPolicy>,std::unique_ptr<BackoffPolicy>,Options)
997 * @see Commit(std::function<StatusOr<Mutations>(Transaction)> const&,std::unique_ptr<TransactionRerunPolicy>,std::unique_ptr<BackoffPolicy>,Options)
998 */
999 StatusOr<CommitResult> Commit(
1000 std::function<StatusOr<Mutations>(Transaction)> const& mutator,
1001 std::unique_ptr<TransactionRerunPolicy> rerun_policy,
1002 std::unique_ptr<BackoffPolicy> backoff_policy,
1003 CommitOptions const& commit_options) {
1004 return Commit(mutator, std::move(rerun_policy), std::move(backoff_policy),
1005 Options(commit_options));
1006 }
1007 /**
1008 * @copybrief Commit(std::function<StatusOr<Mutations>(Transaction)> const&,std::unique_ptr<TransactionRerunPolicy>,std::unique_ptr<BackoffPolicy>,Options)
1009 * @see Commit(std::function<StatusOr<Mutations>(Transaction)> const&,std::unique_ptr<TransactionRerunPolicy>,std::unique_ptr<BackoffPolicy>,Options)
1010 */
1011 StatusOr<CommitResult> Commit(
1012 std::function<StatusOr<Mutations>(Transaction)> const& mutator,
1013 std::unique_ptr<TransactionRerunPolicy> rerun_policy,
1014 std::unique_ptr<BackoffPolicy> backoff_policy,
1015 std::initializer_list<internal::NonConstructible>) {
1016 return Commit(mutator, std::move(rerun_policy), std::move(backoff_policy));
1017 }
1018 ///@}
1019
1020 ///@{
1021 /// @name Backwards compatibility for CommitOptions.
1022 /**
1023 * @copybrief Commit(std::function<StatusOr<Mutations>(Transaction)> const&,Options)
1024 */
1025 StatusOr<CommitResult> Commit(
1026 std::function<StatusOr<Mutations>(Transaction)> const& mutator,
1027 CommitOptions const& commit_options) {
1028 return Commit(mutator, Options(commit_options));
1029 }
1030 /**
1031 * @see Commit(std::function<StatusOr<Mutations>(Transaction)> const&,Options)
1032 */
1033 StatusOr<CommitResult> Commit(
1034 std::function<StatusOr<Mutations>(Transaction)> const& mutator,
1035 std::initializer_list<internal::NonConstructible>) {
1036 return Commit(mutator);
1037 }
1038 ///@}
1039
1040 ///@{
1041 /// @name Backwards compatibility for CommitOptions.
1042 /**
1043 * @copybrief Commit(Mutations,Options)
1044 * @see Commit(Mutations,Options)
1045 */
1046 StatusOr<CommitResult> Commit(Mutations mutations,
1047 CommitOptions const& commit_options) {
1048 return Commit(std::move(mutations), Options(commit_options));
1049 }
1050 /**
1051 * @copybrief Commit(Mutations,Options)
1052 * @see Commit(Mutations,Options)
1053 */
1054 StatusOr<CommitResult> Commit(
1055 Mutations mutations, std::initializer_list<internal::NonConstructible>) {
1056 return Commit(std::move(mutations));
1057 }
1058 ///@}
1059
1060 ///@{
1061 /// @name Backwards compatibility for CommitOptions.
1062 /**
1063 * @copybrief Commit(Transaction,Mutations,Options)
1064 * @see Commit(Transaction,Mutations,Options)
1065 */
1066 StatusOr<CommitResult> Commit(Transaction transaction, Mutations mutations,
1067 CommitOptions const& commit_options) {
1068 return Commit(std::move(transaction), std::move(mutations),
1069 Options(commit_options));
1070 }
1071 /**
1072 * @copybrief Commit(Transaction,Mutations,Options)
1073 * @see Commit(Transaction,Mutations,Options)
1074 */
1075 StatusOr<CommitResult> Commit(
1076 Transaction transaction, Mutations mutations,
1077 std::initializer_list<internal::NonConstructible>) {
1078 return Commit(std::move(transaction), std::move(mutations));
1079 }
1080 ///@}
1081
1082 ///@{
1083 /// @name Backwards compatibility for QueryOptions.
1084 /**
1085 * @copybrief ExecutePartitionedDml(SqlStatement,Options)
1086 * @see ExecutePartitionedDml(SqlStatement,Options)
1087 */
1089 SqlStatement statement, QueryOptions const& opts) {
1090 return ExecutePartitionedDml(std::move(statement), Options(opts));
1091 }
1092 /**
1093 * @copybrief ExecutePartitionedDml(SqlStatement,Options)
1094 * @see ExecutePartitionedDml(SqlStatement,Options)
1095 */
1097 SqlStatement statement,
1098 std::initializer_list<internal::NonConstructible>) {
1099 return ExecutePartitionedDml(std::move(statement));
1100 }
1101 ///@}
1102
1103 private:
1104 std::shared_ptr<Connection> conn_;
1105 Options opts_;
1106};
1107
1108/**
1109 * Returns a Connection object that can be used for interacting with Spanner.
1110 *
1111 * The returned connection object should not be used directly; instead it
1112 * should be given to a `Client` instance, and methods should be invoked on
1113 * `Client`.
1114 *
1115 * The optional @p opts argument may be used to configure aspects of the
1116 * returned `Connection`. Expected options are any of the types in the
1117 * following option lists.
1118 *
1119 * - `google::cloud::CommonOptionList`
1120 * - `google::cloud::GrpcOptionList`
1121 * - `google::cloud::spanner::SpannerPolicyOptionList`
1122 * - `google::cloud::spanner::SessionPoolOptionList`
1123 *
1124 * @note Unrecognized options will be ignored. To debug issues with options set
1125 * `GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes` in the environment and unexpected
1126 * options will be logged.
1127 *
1128 * @see `Connection`
1129 *
1130 * @param db See `Database`.
1131 * @param opts (optional) Configure the `Connection` created by this function.
1132 */
1133std::shared_ptr<spanner::Connection> MakeConnection(spanner::Database const& db,
1134 Options opts = {});
1135
1136/**
1137 * Returns a Connection object that can be used for interacting with Spanner.
1138 *
1139 * The returned connection object should not be used directly, rather it should
1140 * be given to a `Client` instance, and methods should be invoked on `Client`.
1141 *
1142 * @deprecated Please use the `MakeConnection()` overload that accepts
1143 * `google::cloud::Options` instead.
1144 *
1145 * @see `Connection`
1146 *
1147 * @param db See `Database`.
1148 * @param connection_options configure the `Connection` created by this
1149 * function.
1150 * @param session_pool_options (optional) configure the `SessionPool` created
1151 * by the `Connection`.
1152 */
1153std::shared_ptr<Connection> MakeConnection(
1154 Database const& db, ConnectionOptions const& connection_options,
1155 SessionPoolOptions session_pool_options = SessionPoolOptions());
1156
1157/**
1158 * @copydoc MakeConnection(Database const&, ConnectionOptions const&, SessionPoolOptions)
1159 *
1160 * @deprecated Please use the `MakeConnection()` overload that accepts
1161 * `google::cloud::Options` instead.
1162 *
1163 * @par Example
1164 * @snippet samples.cc custom-retry-policy
1165 *
1166 * @param retry_policy override the default `RetryPolicy`, controls how long
1167 * the returned `Connection` object retries requests on transient
1168 * failures.
1169 * @param backoff_policy override the default `BackoffPolicy`, controls how
1170 * long the `Connection` object waits before retrying a failed request.
1171 */
1172std::shared_ptr<Connection> MakeConnection(
1173 Database const& db, ConnectionOptions const& connection_options,
1174 SessionPoolOptions session_pool_options,
1175 std::unique_ptr<RetryPolicy> retry_policy,
1176 std::unique_ptr<BackoffPolicy> backoff_policy);
1177
1178GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
1179} // namespace spanner
1180} // namespace cloud
1181} // namespace google
1182
1183#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CLIENT_H
ClientOptions allows the caller to set a variety of options when constructing a Client instance.
Definition: client_options.h:31
Performs database client operations on Spanner.
Definition: client.h:124
StatusOr< PartitionedDmlResult > ExecutePartitionedDml(SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Executes a Partitioned DML SQL query.
Definition: client.h:1096
ProfileQueryResult ProfileQuery(Transaction::SingleUseOptions transaction_options, SqlStatement statement, QueryOptions const &opts)
Profiles a SQL query.
Definition: client.h:873
StatusOr< std::vector< ReadPartition > > PartitionRead(Transaction transaction, std::string table, KeySet keys, std::vector< std::string > columns, Options opts={})
Creates a set of partitions that can be used to execute a read operation in parallel.
ProfileQueryResult ProfileQuery(Transaction transaction, SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Profiles a SQL query.
Definition: client.h:902
StatusOr< PartitionedDmlResult > ExecutePartitionedDml(SqlStatement statement, Options opts={})
Executes a Partitioned DML SQL query.
StatusOr< ProfileDmlResult > ProfileDml(Transaction transaction, SqlStatement statement, QueryOptions const &opts)
Executes a SQL query.
Definition: client.h:957
StatusOr< CommitResult > Commit(std::function< StatusOr< Mutations >(Transaction)> const &mutator, std::unique_ptr< TransactionRerunPolicy > rerun_policy, std::unique_ptr< BackoffPolicy > backoff_policy, CommitOptions const &commit_options)
Commits a read-write transaction.
Definition: client.h:999
RowStream ExecuteQuery(Transaction::SingleUseOptions transaction_options, SqlStatement statement, Options opts={})
Executes a SQL query.
StatusOr< DmlResult > ExecuteDml(Transaction transaction, SqlStatement statement, QueryOptions const &opts)
Executes a SQL DML statement.
Definition: client.h:938
RowStream Read(std::string table, KeySet keys, std::vector< std::string > columns, Options opts={})
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
ProfileQueryResult ProfileQuery(Transaction::SingleUseOptions transaction_options, SqlStatement statement, Options opts={})
Profiles a SQL query.
StatusOr< CommitResult > Commit(std::function< StatusOr< Mutations >(Transaction)> const &mutator, CommitOptions const &commit_options)
Commits a read-write transaction.
Definition: client.h:1025
RowStream Read(Transaction::SingleUseOptions transaction_options, std::string table, KeySet keys, std::vector< std::string > columns, ReadOptions const &read_options)
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
Definition: client.h:712
friend bool operator!=(Client const &a, Client const &b)
Definition: client.h:153
RowStream ExecuteQuery(SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Executes a SQL query.
Definition: client.h:793
StatusOr< BatchDmlResult > ExecuteBatchDml(Transaction transaction, std::vector< SqlStatement > statements, Options opts={})
Executes a batch of SQL DML statements.
StatusOr< std::vector< ReadPartition > > PartitionRead(Transaction transaction, std::string table, KeySet keys, std::vector< std::string > columns, std::initializer_list< internal::NonConstructible >)
Creates a set of partitions that can be used to execute a read operation in parallel.
Definition: client.h:771
Status Rollback(Transaction transaction, Options opts={})
Rolls back a read-write transaction, releasing any locks it holds.
StatusOr< CommitResult > Commit(std::function< StatusOr< Mutations >(Transaction)> const &mutator, std::unique_ptr< TransactionRerunPolicy > rerun_policy, std::unique_ptr< BackoffPolicy > backoff_policy, std::initializer_list< internal::NonConstructible >)
Commits a read-write transaction.
Definition: client.h:1011
RowStream Read(Transaction::SingleUseOptions transaction_options, std::string table, KeySet keys, std::vector< std::string > columns, Options opts={})
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
RowStream Read(Transaction::SingleUseOptions transaction_options, std::string table, KeySet keys, std::vector< std::string > columns, std::initializer_list< internal::NonConstructible >)
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
Definition: client.h:723
ProfileQueryResult ProfileQuery(Transaction transaction, SqlStatement statement, QueryOptions const &opts)
Profiles a SQL query.
Definition: client.h:892
RowStream ExecuteQuery(Transaction transaction, SqlStatement statement, QueryOptions const &opts)
Executes a SQL query.
Definition: client.h:819
StatusOr< std::vector< QueryPartition > > PartitionQuery(Transaction transaction, SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Creates a set of partitions that can be used to execute a query operation in parallel.
Definition: client.h:925
StatusOr< CommitResult > Commit(Mutations mutations, CommitOptions const &commit_options)
Commits the mutations, using the options, atomically in order.
Definition: client.h:1046
StatusOr< CommitResult > CommitAtLeastOnce(Transaction::ReadWriteOptions transaction_options, Mutations mutations, Options opts={})
Commits a write transaction with at-least-once semantics.
StatusOr< CommitResult > Commit(Transaction transaction, Mutations mutations, CommitOptions const &commit_options)
Commits a read-write transaction.
Definition: client.h:1066
ProfileQueryResult ProfileQuery(Transaction transaction, SqlStatement statement, Options opts={})
Profiles a SQL query.
Client(Client const &)=default
StatusOr< std::vector< QueryPartition > > PartitionQuery(Transaction transaction, SqlStatement statement, Options opts=Options{})
Creates a set of partitions that can be used to execute a query operation in parallel.
StatusOr< ProfileDmlResult > ProfileDml(Transaction transaction, SqlStatement statement, Options opts={})
Profiles a SQL DML statement.
StatusOr< CommitResult > Commit(Transaction transaction, Mutations mutations, std::initializer_list< internal::NonConstructible >)
Commits a read-write transaction.
Definition: client.h:1075
StatusOr< PartitionedDmlResult > ExecutePartitionedDml(SqlStatement statement, QueryOptions const &opts)
Executes a Partitioned DML SQL query.
Definition: client.h:1088
ProfileQueryResult ProfileQuery(Transaction::SingleUseOptions transaction_options, SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Profiles a SQL query.
Definition: client.h:883
StatusOr< CommitResult > Commit(std::function< StatusOr< Mutations >(Transaction)> const &mutator, std::initializer_list< internal::NonConstructible >)
Definition: client.h:1033
RowStream ExecuteQuery(Transaction transaction, SqlStatement statement, Options opts={})
Executes a SQL query.
RowStream ExecuteQuery(QueryPartition const &partition, QueryOptions const &opts)
Executes a SQL query on a subset of rows in a database.
Definition: client.h:836
StatusOr< ExecutionPlan > AnalyzeSql(Transaction transaction, SqlStatement statement, QueryOptions const &opts)
Analyzes the execution plan of a SQL statement.
Definition: client.h:976
RowStream Read(ReadPartition const &partition, Options opts={})
Reads rows from a subset of rows in a database.
RowStream Read(std::string table, KeySet keys, std::vector< std::string > columns, ReadOptions const &read_options)
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
Definition: client.h:693
ProfileQueryResult ProfileQuery(SqlStatement statement, QueryOptions const &opts)
Profiles a SQL query.
Definition: client.h:856
ProfileQueryResult ProfileQuery(SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Profiles a SQL query.
Definition: client.h:864
RowStream ExecuteQuery(SqlStatement statement, Options opts={})
Executes a SQL query.
StatusOr< CommitResult > Commit(Mutations mutations, Options opts={})
Commits the mutations, using the options, atomically in order.
RowStream ExecuteQuery(Transaction transaction, SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Executes a SQL query.
Definition: client.h:828
friend bool operator==(Client const &a, Client const &b)
Definition: client.h:150
StatusOr< CommitResult > Commit(Mutations mutations, std::initializer_list< internal::NonConstructible >)
Commits the mutations, using the options, atomically in order.
Definition: client.h:1054
StatusOr< CommitResult > Commit(std::function< StatusOr< Mutations >(Transaction)> const &mutator, Options opts={})
Commits a read-write transaction.
RowStream ExecuteQuery(Transaction::SingleUseOptions transaction_options, SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Executes a SQL query.
Definition: client.h:810
Client()=delete
No default construction.
RowStream Read(Transaction transaction, std::string table, KeySet keys, std::vector< std::string > columns, Options opts={})
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
RowStream Read(std::string table, KeySet keys, std::vector< std::string > columns, std::initializer_list< internal::NonConstructible >)
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
Definition: client.h:703
RowStream ExecuteQuery(SqlStatement statement, QueryOptions const &opts)
Executes a SQL query.
Definition: client.h:786
ProfileQueryResult ProfileQuery(SqlStatement statement, Options opts={})
Profiles a SQL query.
StatusOr< ProfileDmlResult > ProfileDml(Transaction transaction, SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Executes a SQL query.
Definition: client.h:963
RowStream ExecuteQuery(QueryPartition const &partition, std::initializer_list< internal::NonConstructible >)
Executes a SQL query on a subset of rows in a database.
Definition: client.h:844
RowStream Read(Transaction transaction, std::string table, KeySet keys, std::vector< std::string > columns, std::initializer_list< internal::NonConstructible >)
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
Definition: client.h:744
StatusOr< DmlResult > ExecuteDml(Transaction transaction, SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Executes a SQL DML statement.
Definition: client.h:948
Client & operator=(Client &&)=default
StatusOr< std::vector< QueryPartition > > PartitionQuery(Transaction transaction, SqlStatement statement, PartitionOptions const &partition_options)
Creates a set of partitions that can be used to execute a query operation in parallel.
Definition: client.h:915
StatusOr< ExecutionPlan > AnalyzeSql(Transaction transaction, SqlStatement statement, std::initializer_list< internal::NonConstructible >)
Analyzes the execution plan of a SQL statement.
Definition: client.h:986
StatusOr< CommitResult > Commit(Transaction transaction, Mutations mutations, Options opts={})
Commits a read-write transaction.
StatusOr< std::vector< ReadPartition > > PartitionRead(Transaction transaction, std::string table, KeySet keys, std::vector< std::string > columns, ReadOptions const &read_options, PartitionOptions const &partition_options)
Creates a set of partitions that can be used to execute a read operation in parallel.
Definition: client.h:758
StatusOr< ExecutionPlan > AnalyzeSql(Transaction transaction, SqlStatement statement, Options opts={})
Analyzes the execution plan of a SQL statement.
Client(std::shared_ptr< Connection > conn, Options opts={})
Constructs a Client object using the specified conn and opts.
Definition: client.h:133
StatusOr< CommitResult > Commit(std::function< StatusOr< Mutations >(Transaction)> const &mutator, std::unique_ptr< TransactionRerunPolicy > rerun_policy, std::unique_ptr< BackoffPolicy > backoff_policy, Options opts={})
Commits a read-write transaction.
RowStream Read(Transaction transaction, std::string table, KeySet keys, std::vector< std::string > columns, ReadOptions const &read_options)
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ...
Definition: client.h:734
Client & operator=(Client const &)=default
RowStream ExecuteQuery(QueryPartition const &partition, Options opts={})
Executes a SQL query on a subset of rows in a database.
StatusOr< DmlResult > ExecuteDml(Transaction transaction, SqlStatement statement, Options opts={})
Executes a SQL DML statement.
Client(std::shared_ptr< Connection > conn, std::initializer_list< internal::NonConstructible >)
Definition: client.h:682
RowStream ExecuteQuery(Transaction::SingleUseOptions transaction_options, SqlStatement statement, QueryOptions const &opts)
Executes a SQL query.
Definition: client.h:801
Client(std::shared_ptr< Connection > conn, ClientOptions const &opts)
Definition: client.h:680
Set options on calls to spanner::Client::Commit().
Definition: commit_options.h:35
A connection to a Spanner database instance.
Definition: connection.h:59
virtual Options options()
Returns the options used by the Connection.
Definition: connection.h:134
This class identifies a Cloud Spanner Database.
Definition: database.h:43
Represents the result of a data modifying operation using spanner::Client::ExecuteDml().
Definition: results.h:146
The KeySet class is a regular type that represents a collection of Keys.
Definition: keys.h:157
Represents the result and profile stats of a data modifying operation using spanner::Client::ProfileD...
Definition: results.h:244
Represents the stream of Rows and profile stats returned from spanner::Client::ProfileQuery().
Definition: results.h:186
These QueryOptions allow users to configure features about how their SQL queries executes on the serv...
Definition: query_options.h:37
The QueryPartition class is a regular type that represents a single slice of a parallel SQL read.
Definition: query_partition.h:89
The ReadPartition class is a regular type that represents a single slice of a parallel Read operation...
Definition: read_partition.h:90
Represents the stream of Rows returned from spanner::Client::Read() or spanner::Client::ExecuteQuery(...
Definition: results.h:101
Controls the session pool maintained by a spanner::Client.
Definition: session_pool_options.h:60
SessionPoolOptions()
Definition: session_pool_options.h:62
Represents a potentially parameterized SQL statement.
Definition: sql_statement.h:51
Options for ReadWrite transactions.
Definition: transaction.h:84
Options for "single-use", ReadOnly transactions, where Spanner chooses the read timestamp,...
Definition: transaction.h:108
The representation of a Cloud Spanner transaction.
Definition: transaction.h:58
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
Options ToOptions(PartitionOptions const &)
Converts PartitionOptions to common Options.
std::shared_ptr< Connection > MakeConnection(Database const &db, ConnectionOptions const &connection_options, SessionPoolOptions session_pool_options, std::unique_ptr< RetryPolicy > retry_policy, std::unique_ptr< BackoffPolicy > backoff_policy)
Returns a Connection object that can be used for interacting with Spanner.
Options ToOptions(ReadOptions const &)
Converts ReadOptions to common Options.
std::shared_ptr< Connection > MakeConnection(Database const &db, ConnectionOptions const &connection_options, SessionPoolOptions session_pool_options=SessionPoolOptions())
Returns a Connection object that can be used for interacting with Spanner.
std::shared_ptr< spanner::Connection > MakeConnection(spanner::Database const &db, Options opts={})
Returns a Connection object that can be used for interacting with Spanner.
The result of executing a batch of DML statements.
Definition: batch_dml_result.h:39
The result of committing a Transaction.
Definition: commit_result.h:38
Options passed to Client::PartitionRead or Client::PartitionQuery.
Definition: partition_options.h:38
The result of executing a Partitioned DML query.
Definition: partitioned_dml_result.h:29
Options passed to Client::Read or Client::PartitionRead.
Definition: read_options.h:32