Cloud Spanner C++ Client Library
The Cloud Spanner C++ Client library offers types and functions to use Cloud Spanner from C++ applications.
Quickstart
The following "Hello World" program should give you a sense of how to use this library. This program is also used to illustrate how to incorporate the library into your project.
#include "google/cloud/spanner/client.h"
#include <iostream>
int main(int argc, char* argv[]) {
if (argc != 4) {
std::cerr << "Usage: " << argv[0]
<< " project-id instance-id database-id\n";
return 1;
}
namespace spanner = ::google::cloud::spanner;
spanner::Client client(
spanner::MakeConnection(spanner::Database(argv[1], argv[2], argv[3])));
auto rows =
client.ExecuteQuery(spanner::SqlStatement("SELECT 'Hello World'"));
for (auto const& row : spanner::StreamOf<std::tuple<std::string>>(rows)) {
if (!row) {
std::cerr << row.status() << "\n";
return 1;
}
std::cout << std::get<0>(*row) << "\n";
}
return 0;
}
More Information
- Read more about Cloud Spanner
Client::ExecuteQuery()
to execute SQL queries in Cloud Spanner.Client::Commit()
to execute read-write transactions in Cloud Spanner.Client::Read()
to read the rows in a table.- Error Handling to learn how the library reports run-time errors.
- Environment Variables for environment variables affecting the library. Some of these environment variables enable logging to the console. This can be an effective approach to diagnose runtime problems.
- Override Retry, Backoff, and Re-Run Policies to learn how to override the default retry policies used by the library.
- Override the default endpoint
- Override the authentication configuration
- Mocking the Cloud Spanner C++ Client with Google Mock
- The Setting up your development environment guide describes how to set up a C++ development environment in various platforms, including the Google Cloud C++ client libraries.