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

The KeyBound class is a regular type that represents an open or closed endpoint for a range of keys. More...

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

Public Types

enum  Bound { Bound::kClosed, Bound::kOpen }
 An enum indicating whether the Key is included (closed) or excluded (open). More...
 

Public Member Functions

 KeyBound ()=delete
 Not default constructible. More...
 
 KeyBound (Key key, Bound bound)
 Constructs an instance with the given key and bound. More...
 
Key const & key () const &
 Returns the Key. More...
 
Key && key () &&
 Returns the Key (by move). More...
 
Bound bound () const
 Returns the Bound. More...
 
Copy and move semantics.
 KeyBound (KeyBound const &)=default
 
KeyBoundoperator= (KeyBound const &)=default
 
 KeyBound (KeyBound &&)=default
 
KeyBoundoperator= (KeyBound &&)=default
 

Friends

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

Detailed Description

The KeyBound class is a regular type that represents an open or closed endpoint for a range of keys.

A range of keys is defined by a starting KeyBound and an ending KeyBound, and it logically includes all intermediate keys, optionally including/excluding the bounds.

KeyBounds can be "open", meaning the matching row will be excluded from the results, or "closed" meaning the matching row will be included. KeyBound instances should be created with the MakeKeyBoundOpen() or MakeKeyBoundClosed() factory functions.

Example
auto key_set = spanner::KeySet().AddRange(spanner::MakeKeyBoundOpen(0),
Example
void DeleteData(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;
// Delete each of the albums by individual key, then delete all the singers
// using a key range.
auto delete_albums = spanner::DeleteMutationBuilder(
"Albums", spanner::KeySet()
.AddKey(spanner::MakeKey(1, 1))
.AddKey(spanner::MakeKey(1, 2))
.AddKey(spanner::MakeKey(2, 1))
.AddKey(spanner::MakeKey(2, 2))
.AddKey(spanner::MakeKey(2, 3)))
.Build();
auto delete_singers =
"Singers", spanner::KeySet().AddRange(spanner::MakeKeyBoundClosed(1),
.Build();
auto commit_result =
client.Commit(spanner::Mutations{delete_albums, delete_singers});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
std::cout << "Delete was successful [spanner_delete_data]\n";
}

Definition at line 69 of file keys.h.

Member Enumeration Documentation

◆ Bound

An enum indicating whether the Key is included (closed) or excluded (open).

Enumerator
kClosed 
kOpen 

Definition at line 73 of file keys.h.

Constructor & Destructor Documentation

◆ KeyBound() [1/4]

google::cloud::spanner::v1::KeyBound::KeyBound ( )
delete

Not default constructible.

◆ KeyBound() [2/4]

google::cloud::spanner::v1::KeyBound::KeyBound ( Key  key,
Bound  bound 
)
inline

Constructs an instance with the given key and bound.

Definition at line 79 of file keys.h.

◆ KeyBound() [3/4]

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

◆ KeyBound() [4/4]

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

Member Function Documentation

◆ bound()

Bound google::cloud::spanner::v1::KeyBound::bound ( ) const
inline

Returns the Bound.

Definition at line 96 of file keys.h.

◆ key() [1/2]

Key const& google::cloud::spanner::v1::KeyBound::key ( ) const &
inline

Returns the Key.

Definition at line 90 of file keys.h.

◆ key() [2/2]

Key&& google::cloud::spanner::v1::KeyBound::key ( ) &&
inline

Returns the Key (by move).

Definition at line 93 of file keys.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Friends And Related Function Documentation

◆ operator!=

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

Definition at line 101 of file keys.h.

◆ operator==

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

Definition at line 46 of file keys.cc.