Google Cloud Spanner C++ Client  1.32.1
A C++ Client Library for Google Cloud Spanner
Classes | Public Member Functions | List of all members
google::cloud::spanner::v1::Row Class Reference

A Row is a sequence of columns each with a name and an associated Value. More...

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

Public Member Functions

 Row ()
 Default constructs an empty row with no columns nor values. More...
 
std::size_t size () const
 Returns the number of columns in the row. More...
 
std::vector< std::string > const & columns () const
 Returns the column names for the row. More...
 
std::vector< Value > const & values () const &
 Returns the Value objects in the given row. More...
 
std::vector< Value > && values () &&
 Returns the Value objects in the given row. More...
 
StatusOr< Valueget (std::size_t pos) const
 Returns the Value at the given pos. More...
 
StatusOr< Valueget (std::string const &name) const
 Returns the Value in the column with name. More...
 
template<typename T , typename Arg >
StatusOr< T > get (Arg &&arg) const
 Returns the native C++ value at the given position or column name. More...
 
template<typename Tuple >
StatusOr< Tuple > get () const &
 Returns all the native C++ values for the whole row in a std::tuple with the specified type. More...
 
template<typename Tuple >
StatusOr< Tuple > get () &&
 Returns all the native C++ values for the whole row in a std::tuple with the specified type. More...
 
Copy and move.
 Row (Row const &)=default
 
Rowoperator= (Row const &)=default
 
 Row (Row &&)=default
 
Rowoperator= (Row &&)=default
 

Friends

Equality
bool operator== (Row const &a, Row const &b)
 
bool operator!= (Row const &a, Row const &b)
 

Detailed Description

A Row is a sequence of columns each with a name and an associated Value.

The Row class is a regular value type that may be copied, moved, assigned, compared for equality, etc. Instances may be large if they hold lots of Value data, so copy only when necessary.

Row instances are typically returned as the result of queries or reads of a Cloud Spanner table (see Client::Read and Client::ExecuteQuery). Users will mostly just use the accessor methods on Row, and will rarely (if ever) need to construct aRow` of their own.

The number of columns in a Row can be obtained from the size() member function. The Values can be obtained using the values() accessor. The names of each column in the row can be obtained using the columns() accessor.

Perhaps the most convenient way to access the Values in a row is through the variety of "get" accessors. A user may access a column's ‘Value’ by calling get with a std::size_t 0-indexed position, or a std::string column name. Furthermore, callers may directly extract the native C++ type by specifying the C++ type along with the column's position or name.

Example
Row row = ...;
if (StatusOr<std::string> x = row.get<std::string>("LastName")) {
std::cout << "LastName=" << *x << "\n";
}
Row()
Default constructs an empty row with no columns nor values.
Definition: row.cc:46
Note
There is a helper function defined below named MakeTestRow() to make creating Row instances for testing easier.

Definition at line 85 of file row.h.

Constructor & Destructor Documentation

◆ Row() [1/3]

google::cloud::spanner::v1::Row::Row ( )

Default constructs an empty row with no columns nor values.

Definition at line 46 of file row.cc.

◆ Row() [2/3]

google::cloud::spanner::v1::Row::Row ( Row const &  )
default

◆ Row() [3/3]

google::cloud::spanner::v1::Row::Row ( Row &&  )
default

Member Function Documentation

◆ columns()

std::vector<std::string> const& google::cloud::spanner::v1::Row::columns ( ) const
inline

Returns the column names for the row.

Definition at line 102 of file row.h.

◆ get() [1/5]

template<typename Tuple >
StatusOr<Tuple> google::cloud::spanner::v1::Row::get ( ) &&
inline

Returns all the native C++ values for the whole row in a std::tuple with the specified type.

Template Parameters
Tuplethe std::tuple type that the whole row must unpack into.

Definition at line 156 of file row.h.

◆ get() [2/5]

template<typename Tuple >
StatusOr<Tuple> google::cloud::spanner::v1::Row::get ( ) const &
inline

Returns all the native C++ values for the whole row in a std::tuple with the specified type.

Template Parameters
Tuplethe std::tuple type that the whole row must unpack into.

Definition at line 136 of file row.h.

◆ get() [3/5]

template<typename T , typename Arg >
StatusOr<T> google::cloud::spanner::v1::Row::get ( Arg &&  arg) const
inline

Returns the native C++ value at the given position or column name.

Template Parameters
Tthe native C++ type, e.g., std::int64_t or std::string
Arga deduced parameter convertible to a std::size_t or std::string

Definition at line 123 of file row.h.

◆ get() [4/5]

StatusOr< Value > google::cloud::spanner::v1::Row::get ( std::size_t  pos) const

Returns the Value at the given pos.

Definition at line 58 of file row.cc.

◆ get() [5/5]

StatusOr< Value > google::cloud::spanner::v1::Row::get ( std::string const &  name) const

Returns the Value in the column with name.

Definition at line 64 of file row.cc.

◆ operator=() [1/2]

Row& google::cloud::spanner::v1::Row::operator= ( Row &&  )
default

◆ operator=() [2/2]

Row& google::cloud::spanner::v1::Row::operator= ( Row const &  )
default

◆ size()

std::size_t google::cloud::spanner::v1::Row::size ( ) const
inline

Returns the number of columns in the row.

Definition at line 99 of file row.h.

◆ values() [1/2]

std::vector<Value>&& google::cloud::spanner::v1::Row::values ( ) &&
inline

Returns the Value objects in the given row.

Definition at line 108 of file row.h.

◆ values() [2/2]

std::vector<Value> const& google::cloud::spanner::v1::Row::values ( ) const &
inline

Returns the Value objects in the given row.

Definition at line 105 of file row.h.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( Row const &  a,
Row const &  b 
)
friend

Definition at line 172 of file row.h.

◆ operator==

bool operator== ( Row const &  a,
Row const &  b 
)
friend

Definition at line 70 of file row.cc.