Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
google::cloud::spanner::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";
}
A Row is a sequence of columns each with a name and an associated Value.
Definition: row.h:84
StatusOr< Value > get(std::size_t pos) const
Returns the Value at the given pos.

Constructor & Destructor Documentation

◆ Row() [1/3]

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

Default constructs an empty row with no columns nor values.

◆ Row() [2/3]

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

◆ Row() [3/3]

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

Member Function Documentation

◆ columns()

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

Returns the column names for the row.

◆ get() [1/5]

template<typename Tuple >
StatusOr< Tuple > google::cloud::spanner::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.

◆ get() [2/5]

template<typename Tuple >
StatusOr< Tuple > google::cloud::spanner::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.

◆ get() [3/5]

template<typename T , typename Arg >
StatusOr< T > google::cloud::spanner::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

◆ get() [4/5]

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

Returns the Value at the given pos.

◆ get() [5/5]

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

Returns the Value in the column with name.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ size()

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

Returns the number of columns in the row.

◆ values() [1/2]

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

Returns the Value objects in the given row.

◆ values() [2/2]

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

Returns the Value objects in the given row.

Friends And Related Function Documentation

◆ operator!=

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

◆ operator==

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