Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
google::cloud::spanner::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::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 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.

Member Typedef Documentation

◆ iterator

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

Member Function Documentation

◆ begin()

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

◆ end()

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

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::move(row).status();
std::cout << " SingerId: " << std::get<0>(*row) << "\n"
<< " FirstName: " << std::get<1>(*row) << "\n"
<< " LastName: " << std::get<2>(*row) << "\n";
}
std::cout << "end of results\n";
}
Performs database client operations on Spanner.
Definition: client.h:124
RowStream ExecuteQuery(SqlStatement statement, Options opts={})
Executes a SQL query.
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:446
Note
Ownership of the range is not transferred, so it must outlive the returned TupleStream.
Template Parameters
RowRangemust be a range defined by RowStreamIterators.