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

The KeySet class is a regular type that represents a collection of Keys. More...

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

Public Member Functions

 KeySet ()=default
 Constructs an empty KeySet. More...
 
 KeySet (KeySet const &)=default
 
KeySetoperator= (KeySet const &)=default
 
 KeySet (KeySet &&)=default
 
KeySetoperator= (KeySet &&)=default
 
KeySetAddKey (Key key)
 Adds the given key to the KeySet. More...
 
KeySetAddRange (KeyBound start, KeyBound end)
 Adds a range of keys defined by the given KeyBounds. More...
 

Static Public Member Functions

static KeySet All ()
 Returns a KeySet that represents the set of "All" keys for the index. More...
 

Friends

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

Detailed Description

The KeySet class is a regular type that represents a collection of Keys.

Users can construct a KeySet instance, then add Keys and ranges of Keys to the set. The caller is responsible for ensuring that all keys in a given KeySet instance contain the same number and types of values.

Users may also optionally construct an instance that represents all keys with KeySet::All().

Example
auto delete_albums = spanner::DeleteMutationBuilder(
"Albums", spanner::KeySet()
.Build();
The KeySet class is a regular type that represents a collection of Keys.
Definition: keys.h:157
KeySet & AddKey(Key key)
Adds the given key to the KeySet.
Definition: keys.cc:37
Key MakeKey(Ts &&... ts)
Constructs a Key from the given arguments.
Definition: keys.h:51
spanner_internal::DeleteMutationBuilder DeleteMutationBuilder
A helper class to construct "delete" mutations.
Definition: mutations.h:355
Example
void DeleteAll(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;
// Delete all the performances, venues, albums and singers.
auto commit = client.Commit(spanner::Mutations{
spanner::MakeDeleteMutation("Performances", spanner::KeySet::All()),
spanner::MakeDeleteMutation("Venues", spanner::KeySet::All()),
spanner::MakeDeleteMutation("Albums", spanner::KeySet::All()),
spanner::MakeDeleteMutation("Singers", spanner::KeySet::All()),
});
if (!commit) throw std::runtime_error(commit.status().message());
std::cout << "delete-all was successful\n";
}
Performs database client operations on Spanner.
Definition: client.h:122
StatusOr< CommitResult > Commit(std::function< StatusOr< Mutations >(Transaction)> const &mutator, std::unique_ptr< TransactionRerunPolicy > rerun_policy, std::unique_ptr< BackoffPolicy > backoff_policy, CommitOptions const &options={})
Commits a read-write transaction.
Definition: client.cc:191
std::vector< Mutation > Mutations
An ordered sequence of mutations to pass to Client::Commit() or return from the Client::Commit() muta...
Definition: mutations.h:99
Mutation MakeDeleteMutation(std::string table_name, KeySet keys)
Creates a simple "delete" mutation for the values in keys.
Definition: mutations.h:369
Contains all the Cloud Spanner C++ client types and functions.
Definition: backup.cc:21

Definition at line 157 of file keys.h.

Constructor & Destructor Documentation

◆ KeySet() [1/3]

google::cloud::spanner::v1::KeySet::KeySet ( )
default

Constructs an empty KeySet.

◆ KeySet() [2/3]

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

◆ KeySet() [3/3]

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

Member Function Documentation

◆ AddKey()

KeySet & google::cloud::spanner::v1::KeySet::AddKey ( Key  key)

Adds the given key to the KeySet.

Example
auto delete_albums = spanner::DeleteMutationBuilder(
"Albums", spanner::KeySet()
.Build();

Definition at line 37 of file keys.cc.

◆ AddRange()

KeySet & google::cloud::spanner::v1::KeySet::AddRange ( KeyBound  start,
KeyBound  end 
)

Adds a range of keys defined by the given KeyBounds.

Example
auto delete_albums = spanner::DeleteMutationBuilder(
"Albums", spanner::KeySet()
.Build();

Definition at line 43 of file keys.cc.

◆ All()

static KeySet google::cloud::spanner::v1::KeySet::All ( )
inlinestatic

Returns a KeySet that represents the set of "All" keys for the index.

Example
void DeleteAll(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;
// Delete all the performances, venues, albums and singers.
auto commit = client.Commit(spanner::Mutations{
spanner::MakeDeleteMutation("Performances", spanner::KeySet::All()),
spanner::MakeDeleteMutation("Venues", spanner::KeySet::All()),
spanner::MakeDeleteMutation("Albums", spanner::KeySet::All()),
spanner::MakeDeleteMutation("Singers", spanner::KeySet::All()),
});
if (!commit) throw std::runtime_error(commit.status().message());
std::cout << "delete-all was successful\n";
}

Definition at line 165 of file keys.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

Friends And Related Function Documentation

◆ operator!=

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

Definition at line 199 of file keys.h.

◆ operator==

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

Definition at line 57 of file keys.cc.