Google Cloud Spanner C++ Client  1.32.0
A C++ Client Library for Google Cloud Spanner
Public Types | Public Member Functions | Friends | List of all members
google::cloud::spanner::v1::TupleStream< Tuple > Class Template Reference

A TupleStream<Tuple> defines a range that parses Tuple objects from the given range of RowStreamIterators. More...

#include <google/cloud/spanner/row.h>

Public Types

using iterator = TupleStreamIterator< Tuple >
 

Public Member Functions

iterator begin () const
 
iterator end () const
 

Friends

template<typename T , typename RowRange >
TupleStream< T > StreamOf (RowRange &&range)
 A factory that creates a TupleStream<Tuple> by wrapping the given range. More...
 

Detailed Description

template<typename Tuple>
class google::cloud::spanner::v1::TupleStream< Tuple >

A TupleStream<Tuple> defines a range that parses Tuple objects from the given range of RowStreamIterators.

Users create instances using the StreamOf<T>(range) non-member factory function (defined below). The following is a typical usage of this class in a range-for loop.

auto row_range = ...
using RowType = std::tuple<std::int64_t, std::string, bool>;
for (auto const& row : StreamOf<RowType>(row_range)) {
if (!row) {
// Handle error;
}
std::int64_t x = std::get<0>(*row);
...
}
Note
The term "stream" in this name refers to the general nature of the the data source, and is not intended to suggest any similarity to C++'s I/O streams library. Syntactically, this class is a "range" defined by two "iterator" objects of type TupleStreamIterator<Tuple>.
Template Parameters
Tuplethe std::tuple<...> to parse each Row into.

Definition at line 410 of file row.h.

Member Typedef Documentation

◆ iterator

template<typename Tuple >
using google::cloud::spanner::v1::TupleStream< Tuple >::iterator = TupleStreamIterator<Tuple>

Definition at line 412 of file row.h.

Member Function Documentation

◆ begin()

template<typename Tuple >
iterator google::cloud::spanner::v1::TupleStream< Tuple >::begin ( ) const
inline

Definition at line 416 of file row.h.

◆ end()

template<typename Tuple >
iterator google::cloud::spanner::v1::TupleStream< Tuple >::end ( ) const
inline

Definition at line 417 of file row.h.

Friends And Related Function Documentation

◆ StreamOf

template<typename Tuple >
template<typename T , typename RowRange >
TupleStream<T> StreamOf ( RowRange &&  range)
friend

A factory that creates a TupleStream<Tuple> by wrapping the given range.

The RowRange must be a range defined by RowStreamIterator objects.

namespace spanner = ::google::cloud::spanner;
std::cout << "Querying the Singers table:\n";
auto query = client.ExecuteQuery(spanner::SqlStatement(
"SELECT SingerId, FirstName, LastName FROM Singers"));
using RowType = std::tuple<std::int64_t, std::string, std::string>;
for (auto& row : spanner::StreamOf<RowType>(query)) {
if (!row) throw std::runtime_error(row.status().message());
std::cout << " FirstName: " << std::get<0>(*row)
<< "\n LastName: " << std::get<1>(*row) << "\n";
}
std::cout << "end of results\n";
}
Performs database client operations on Spanner.
Definition: client.h:122
RowStream ExecuteQuery(SqlStatement statement, QueryOptions const &opts={})
Executes a SQL query.
Definition: client.cc:87
Represents a potentially parameterized SQL statement.
Definition: sql_statement.h:51
friend TupleStream< T > StreamOf(RowRange &&range)
A factory that creates a TupleStream<Tuple> by wrapping the given range.
Definition: row.h:444
Contains all the Cloud Spanner C++ client types and functions.
Definition: backup.cc:21
Note
Ownership of the range is not transferred, so it must outlive the returned TupleStream.
Template Parameters
RowRangemust be a range defined by RowStreamIterators.

Definition at line 444 of file row.h.