Class KeySet (2.22.0)

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()
                                         .AddKey(spanner::MakeKey(2, 1))
                                         .AddKey(spanner::MakeKey(2, 3)))
                           .Build();
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::move(commit).status();
  std::cout << "delete-all was successful\n";
}

Constructors

KeySet()

Constructs an empty KeySet.

KeySet(KeySet const &)

Parameter
NameDescription
KeySet const &

KeySet(KeySet &&)

Parameter
NameDescription
KeySet &&

Operators

operator=(KeySet const &)

Parameter
NameDescription
KeySet const &
Returns
TypeDescription
KeySet &

operator=(KeySet &&)

Parameter
NameDescription
KeySet &&
Returns
TypeDescription
KeySet &

Functions

static All()

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::move(commit).status();
  std::cout << "delete-all was successful\n";
}
Returns
TypeDescription
KeySet

AddKey(Key)

Adds the given key to the KeySet.

Example
  auto delete_albums = spanner::DeleteMutationBuilder(
                           "Albums", spanner::KeySet()
                                         .AddKey(spanner::MakeKey(2, 1))
                                         .AddKey(spanner::MakeKey(2, 3)))
                           .Build();
Parameter
NameDescription
key Key
Returns
TypeDescription
KeySet &

AddRange(KeyBound, KeyBound)

Adds a range of keys defined by the given KeyBounds.

Example
  auto delete_albums = spanner::DeleteMutationBuilder(
                           "Albums", spanner::KeySet()
                                         .AddKey(spanner::MakeKey(2, 1))
                                         .AddKey(spanner::MakeKey(2, 3)))
                           .Build();
Parameters
NameDescription
start KeyBound
end KeyBound
Returns
TypeDescription
KeySet &