Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

docs: add snippets for methods and classes in keys.h #1451

Merged
merged 3 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions google/cloud/spanner/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ using Key = std::vector<Value>;
* Constructs a `Key` from the given arguments.
*
* @par Example
*
* @code
* Key key = MakeKey(123, "hello");
* assert(key.size() == 2);
* assert(key[0] == Value(123));
* assert(key[1] == Value("hello"));
* @endcode
* @snippet samples.cc make-key
*/
template <typename... Ts>
Key MakeKey(Ts&&... ts) {
Expand All @@ -65,6 +59,12 @@ Key MakeKey(Ts&&... ts) {
* the results, or "closed" meaning the matching row will be included.
* `KeyBound` instances should be created with the `MakeKeyBoundOpen()` or
* `MakeKeyBoundClosed()` factory functions.
*
* @par Example
* @snippet samples.cc make-keybound-open
*
* @par Example
* @snippet samples.cc make-keybound-closed
*/
class KeyBound {
public:
Expand Down Expand Up @@ -111,6 +111,9 @@ class KeyBound {
/**
* Returns a "closed" `KeyBound` with a `Key` constructed from the given
* arguments.
*
* @par Example
* @snippet samples.cc make-keybound-closed
*/
template <typename... Ts>
KeyBound MakeKeyBoundClosed(Ts&&... ts) {
Expand All @@ -120,6 +123,9 @@ KeyBound MakeKeyBoundClosed(Ts&&... ts) {
/**
* Returns an "open" `KeyBound` with a `Key` constructed from the given
* arguments.
*
* @par Example
* @snippet samples.cc make-keybound-open
*/
template <typename... Ts>
KeyBound MakeKeyBoundOpen(Ts&&... ts) {
Expand All @@ -141,6 +147,13 @@ KeySet FromProto(::google::spanner::v1::KeySet);
*
* Users may also optionally construct an instance that
* represents all keys with `KeySet::All()`.
*
* @par Example
* @snippet samples.cc keyset-add-key
*
* @par Example
* @snippet samples.cc keyset-all
*
*/
class KeySet {
public:
Expand All @@ -165,10 +178,20 @@ class KeySet {
KeySet(KeySet&&) = default;
KeySet& operator=(KeySet&&) = default;

/// Adds the given @p key to the `KeySet`.
/**
* Adds the given @p key to the `KeySet`.
*
* @par Example
* @snippet samples.cc keyset-add-key
*/
KeySet& AddKey(Key key);

/// Adds a range of keys defined by the given `KeyBound`s.
/**
* Adds a range of keys defined by the given `KeyBound`s.
*
* @par Example
* @snippet samples.cc keyset-add-key
*/
KeySet& AddRange(KeyBound start, KeyBound end);

/// @name Equality
Expand Down
13 changes: 7 additions & 6 deletions google/cloud/spanner/samples/samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,8 @@ void UpdateData(google::cloud::spanner::Client client) {
}
//! [END spanner_update_data]

//! [START spanner_delete_data]
//! [START spanner_delete_data] [make-key] [make-keybound-closed]
//! [keyset-add-key]
void DeleteData(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;

Expand All @@ -1063,7 +1064,7 @@ void DeleteData(google::cloud::spanner::Client client) {
}
std::cout << "Delete was successful [spanner_delete_data]\n";
}
//! [END spanner_delete_data]
//! [END spanner_delete_data] [make-keybound-closed] [make-key] [keyset-add-key]

//! [keyset-all]
void DeleteAll(google::cloud::spanner::Client client) {
Expand Down Expand Up @@ -2432,10 +2433,10 @@ void ProcessRow(google::cloud::spanner::Row const&) {}
void PartitionRead(google::cloud::spanner::Client client) {
namespace spanner = ::google::cloud::spanner;
RemoteConnectionFake remote_connection;
//! [key-set-builder]
auto key_set = spanner::KeySet().AddRange(spanner::MakeKeyBoundClosed(1),
spanner::MakeKeyBoundClosed(10));
//! [key-set-builder]
//! [key-set-builder] [make-keybound-open]
auto key_set = spanner::KeySet().AddRange(spanner::MakeKeyBoundOpen(0),
spanner::MakeKeyBoundOpen(11));
//! [key-set-builder] [make-keybound-open]

//! [partition-read]
spanner::Transaction ro_transaction = spanner::MakeReadOnlyTransaction();
Expand Down