21 #include <boost/algorithm/string/split.hpp> 23 #include <couchbase/internal/nlohmann/json.hpp> 26 #include <couchbase/transactions/document_metadata.hxx> 27 #include <couchbase/transactions/transaction_links.hxx> 32 namespace transactions
42 nlohmann::json value_;
48 const boost::optional<document_metadata> metadata_;
53 : collection_(doc.collection_)
57 , metadata_(doc.metadata_)
63 template<
typename Content>
69 boost::optional<document_metadata>
metadata)
80 template<
typename Content>
84 document.
links().atr_bucket_name(),
85 document.
links().atr_scope_name(),
86 document.
links().atr_collection_name(),
87 document.
links().staged_transaction_id(),
88 document.
links().staged_attempt_id(),
89 document.
links().staged_content<Content>(),
90 document.
links().cas_pre_txn(),
91 document.
links().revid_pre_txn(),
92 document.
links().exptime_pre_txn(),
93 document.
links().crc32_of_staging(),
94 document.
links().op(),
95 document.
links().forward_compat(),
96 document.
links().is_deleted());
104 boost::optional<std::string> atr_id;
105 boost::optional<std::string> transaction_id;
106 boost::optional<std::string> attempt_id;
107 boost::optional<nlohmann::json> staged_content;
108 boost::optional<std::string> atr_bucket_name;
109 boost::optional<std::string> atr_scope_name;
110 boost::optional<std::string> atr_collection_name;
111 boost::optional<nlohmann::json> forward_compat;
114 boost::optional<std::string> cas_pre_txn;
115 boost::optional<std::string> revid_pre_txn;
116 boost::optional<uint32_t> exptime_pre_txn;
117 boost::optional<std::string> crc32_of_staging;
120 boost::optional<std::string> cas_from_doc;
121 boost::optional<std::string> revid_from_doc;
122 boost::optional<uint32_t> exptime_from_doc;
123 boost::optional<std::string> crc32_from_doc;
125 boost::optional<std::string> op;
128 if (res.
values[0].value) {
129 atr_id = res.
values[0].value->get<std::string>();
131 if (res.
values[1].value) {
132 transaction_id = res.
values[1].value->get<std::string>();
134 if (res.
values[2].value) {
135 attempt_id = res.
values[2].value->get<std::string>();
137 if (res.
values[3].value) {
138 staged_content = res.
values[3].value->get<nlohmann::json>();
140 if (res.
values[4].value) {
141 atr_bucket_name = res.
values[4].value->get<std::string>();
143 if (res.
values[5].value) {
144 std::string name = res.
values[5].value->get<std::string>();
145 std::vector<std::string> splits;
146 boost::split(splits, name, [](
char c) {
return c ==
'.'; });
147 atr_scope_name = splits[0];
148 atr_collection_name = splits[1];
150 if (res.
values[6].value) {
151 nlohmann::json restore = *res.
values[6].value;
152 cas_pre_txn = restore[
"CAS"].get<std::string>();
154 revid_pre_txn = restore[
"revid"].get<std::string>();
155 exptime_pre_txn = restore[
"exptime"].get<uint32_t>();
157 if (res.
values[7].value) {
158 op = res.
values[7].value->get<std::string>();
160 if (res.
values[8].value) {
161 nlohmann::json doc = *res.
values[8].value;
162 cas_from_doc = doc[
"CAS"].get<std::string>();
164 revid_from_doc = doc[
"revid"].get<std::string>();
165 exptime_from_doc = doc[
"exptime"].get<uint32_t>();
166 crc32_from_doc = doc[
"value_crc32c"].get<std::string>();
168 if (res.
values[9].value) {
169 crc32_of_staging = res.
values[9].value.get();
171 if (res.
values[10].value) {
172 forward_compat = res.
values[10].value.get();
174 forward_compat = nlohmann::json::object();
176 if (res.
values[11].value) {
179 content = nlohmann::json::object();
182 transaction_links
links(atr_id,
196 document_metadata md(cas_from_doc, revid_from_doc, exptime_from_doc, crc32_from_doc);
201 template<
typename Content>
204 if (
this != &other) {
205 this->collection_ = other.collection_;
206 this->value_ = other.value_;
207 this->id_ = other.id_;
208 this->links_ = other.links_;
262 template<
typename Content>
263 CB_NODISCARD Content
content()
const 265 return value_.get<Content>();
273 CB_NODISCARD
const std::string&
id()
const 283 CB_NODISCARD uint64_t
cas()
const 289 CB_NODISCARD transaction_links
links()
const 300 template<
typename Content>
321 CB_NODISCARD
const boost::optional<document_metadata>&
metadata()
const 327 template<
typename OStream>
330 os <<
"transaction_get_result{id: " << document.id_ <<
", cas: " << document.cas_
331 <<
", bucket: " << document.collection_.
bucket_name() <<
", coll: " << document.collection_.
name()
332 <<
", links_: " << document.links_ <<
"}";
Definition: bucket.hxx:33
transaction_get_result(const transaction_get_result &doc)
Definition: transaction_get_result.hxx:53
CB_NODISCARD const boost::optional< document_metadata > & metadata() const
Get document metadata.
Definition: transaction_get_result.hxx:327
The result of an operation on a cluster.
Definition: result.hxx:113
Encapsulates results of an individual transaction operation.
Definition: transaction_get_result.hxx:38
friend OStream & operator<<(OStream &os, const transaction_get_result document)
Definition: transaction_get_result.hxx:335
CB_NODISCARD const std::string & name() const
Get name of collection.
Definition: collection.hxx:230
CB_NODISCARD uint64_t cas() const
Get document CAS.
Definition: transaction_get_result.hxx:288
Definition: transaction_links.hxx:33
CB_NODISCARD const std::string & bucket_name() const
Get name of bucket for this collection.
Definition: collection.hxx:250
transaction_get_result & operator=(const transaction_get_result &other)
Definition: transaction_get_result.hxx:207
CB_NODISCARD Content content() const
Content of the document.
Definition: transaction_get_result.hxx:268
static transaction_get_result create_from(transaction_get_result &document, Content content)
Definition: transaction_get_result.hxx:84
uint64_t cas
CAS for document, if any.
Definition: result.hxx:117
CB_NODISCARD transaction_links links() const
Definition: transaction_get_result.hxx:295
std::vector< subdoc_result > values
results of subdoc spec operations
Definition: result.hxx:126
Exposes collection-level kv operations.
Definition: collection.hxx:46
CB_NODISCARD collection & collection_ref()
Collection that contains this document.
Definition: transaction_get_result.hxx:223
CB_NODISCARD const std::string & id() const
Get document id.
Definition: transaction_get_result.hxx:278