Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
Public Member Functions | Static Public Member Functions | Friends | List of all members
couchbase::transactions::transaction_get_result Class Reference

Encapsulates results of an individual transaction operation. More...

#include <transaction_get_result.hxx>

Public Member Functions

 transaction_get_result (const transaction_get_result &doc)
 
template<typename Content >
 transaction_get_result (std::string id, Content content, uint64_t cas, collection &collection, transaction_links links, boost::optional< document_metadata > metadata)
 
template<typename Content >
transaction_get_resultoperator= (const transaction_get_result &other)
 
CB_NODISCARD collectioncollection_ref ()
 Collection that contains this document. More...
 
template<typename Content >
CB_NODISCARD Content content () const
 Content of the document. More...
 
CB_NODISCARD const std::string & id () const
 Get document id. More...
 
CB_NODISCARD uint64_t cas () const
 Get document CAS. More...
 
CB_NODISCARD transaction_links links () const
 
template<typename Content >
void content (const Content &content)
 Set content for this document. More...
 
void cas (uint64_t cas)
 Set document CAS. More...
 
CB_NODISCARD const boost::optional< document_metadata > & metadata () const
 Get document metadata. More...
 

Static Public Member Functions

template<typename Content >
static transaction_get_result create_from (transaction_get_result &document, Content content)
 
static transaction_get_result create_from (collection &collection, std::string id, result res)
 

Friends

template<typename OStream >
OStream & operator<< (OStream &os, const transaction_get_result document)
 

Detailed Description

Encapsulates results of an individual transaction operation.

Constructor & Destructor Documentation

◆ transaction_get_result() [1/2]

couchbase::transactions::transaction_get_result::transaction_get_result ( const transaction_get_result doc)
inline
Stability
Internal:

◆ transaction_get_result() [2/2]

template<typename Content >
couchbase::transactions::transaction_get_result::transaction_get_result ( std::string  id,
Content  content,
uint64_t  cas,
collection collection,
transaction_links  links,
boost::optional< document_metadata metadata 
)
inline
Stability
Internal:

Member Function Documentation

◆ cas() [1/2]

CB_NODISCARD uint64_t couchbase::transactions::transaction_get_result::cas ( ) const
inline

Get document CAS.

Returns
the CAS for this document.

◆ cas() [2/2]

void couchbase::transactions::transaction_get_result::cas ( uint64_t  cas)
inline

Set document CAS.

Parameters
casdesired CAS for document.

◆ collection_ref()

CB_NODISCARD collection& couchbase::transactions::transaction_get_result::collection_ref ( )
inline

Collection that contains this document.

Returns
reference to the collection containing this document.

◆ content() [1/2]

template<typename Content >
CB_NODISCARD Content couchbase::transactions::transaction_get_result::content ( ) const
inline

Content of the document.

The content of the document is stored as json. That is represented internally as a nlohmann::json object. If the documents have a c++ class that represents them, it can be returned here by adding a to_json and from_json helper.

namespace my_namespace {
struct my_doc
{
std::string name;
uint32_t age;
};
void from_json(const nlohmann::json& j, my_doc& d)
{
j.at("name").get_to(d.name);
j.at("age").get_to(d.age);
}
void to_json(nlohmann::json& j, const my_doc& d)
{
j = nlohmann::json({"name", d.name}, {"age", d.age});
}

Then, you can do:

...
txn.run([&](attempt_context& ctx) {
auto txn_doc = ctx.get("mydocid");
my_namespace::my_doc& mydoc = td.content<my_doc>();
...
});

See examples/game_server, and for more detail https://github.com/nlohmann/json#arbitrary-types-conversions

Returns
content of the document.
Examples:
examples/game_server.cxx.

◆ content() [2/2]

template<typename Content >
void couchbase::transactions::transaction_get_result::content ( const Content &  content)
inline

Set content for this document.

Parameters
contentthe desired content. See content() for more details.

◆ create_from() [1/2]

template<typename Content >
static transaction_get_result couchbase::transactions::transaction_get_result::create_from ( transaction_get_result document,
Content  content 
)
inlinestatic
Stability
Internal:

◆ create_from() [2/2]

static transaction_get_result couchbase::transactions::transaction_get_result::create_from ( collection collection,
std::string  id,
result  res 
)
inlinestatic
Stability
Internal:

◆ id()

CB_NODISCARD const std::string& couchbase::transactions::transaction_get_result::id ( ) const
inline

Get document id.

Returns
the id of this document.

◆ links()

CB_NODISCARD transaction_links couchbase::transactions::transaction_get_result::links ( ) const
inline
Stability
Internal:

◆ metadata()

CB_NODISCARD const boost::optional<document_metadata>& couchbase::transactions::transaction_get_result::metadata ( ) const
inline

Get document metadata.

Returns
metadata for this document.

◆ operator=()

template<typename Content >
transaction_get_result& couchbase::transactions::transaction_get_result::operator= ( const transaction_get_result other)
inline
Stability
Internal:

Friends And Related Function Documentation

◆ operator<<

template<typename OStream >
OStream& operator<< ( OStream &  os,
const transaction_get_result  document 
)
friend
Stability
Internal:

The documentation for this class was generated from the following file: