Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
result.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2021 Couchbase, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <boost/optional.hpp>
20 #include <couchbase/internal/nlohmann/json.hpp>
21 #include <couchbase/support.hxx>
22 #include <string>
23 #include <vector>
24 
29 namespace couchbase
30 {
36 struct subdoc_result {
37  boost::optional<nlohmann::json> value;
38  uint32_t status;
39 
41  : status(0)
42  {
43  }
44  subdoc_result(uint32_t s)
45  : status(s)
46  {
47  }
48  subdoc_result(nlohmann::json v, uint32_t s)
49  : value(v)
50  , status(s)
51  {
52  }
53 };
54 
113 struct result {
115  uint32_t rc;
117  uint64_t cas;
119  uint8_t datatype;
120  uint32_t flags;
122  std::string key;
124  boost::optional<nlohmann::json> value;
126  std::vector<subdoc_result> values;
127  bool is_deleted;
128  bool ignore_subdoc_errors;
129 
130  result()
131  : rc(0)
132  , cas(0)
133  , datatype(0)
134  , flags(0)
135  , is_deleted(0)
136  , ignore_subdoc_errors(0)
137  {
138  }
144  CB_NODISCARD std::string strerror() const;
145  CB_NODISCARD bool is_not_found() const;
146  CB_NODISCARD bool is_success() const;
147  CB_NODISCARD bool is_value_too_large() const;
148  CB_NODISCARD bool is_timeout() const;
153  CB_NODISCARD uint32_t error() const;
154  template<typename OStream>
155  friend OStream& operator<<(OStream& os, const result& res)
156  {
157  os << "result{";
158  os << "rc:" << res.rc << ",";
159  os << "strerror:" << res.strerror() << ",";
160  os << "cas:" << res.cas << ",";
161  os << "is_deleted:" << res.is_deleted << ",";
162  os << "datatype:" << res.datatype << ",";
163  os << "flags:" << res.flags;
164  if (res.value) {
165  os << ",value:";
166  os << res.value->dump();
167  }
168  if (!res.values.empty()) {
169  os << ",values:[";
170  for (auto& v : res.values) {
171  os << "{" << (v.value ? v.value->dump() : "") << "," << v.status << "},";
172  }
173  os << "]";
174  }
175  os << "}";
176  return os;
177  }
178 };
179 } // namespace couchbase
CB_NODISCARD std::string strerror() const
Definition: bucket.hxx:33
CB_NODISCARD uint32_t error() const
The result of an operation on a cluster.
Definition: result.hxx:113
uint8_t datatype
datatype flag for content
Definition: result.hxx:119
std::string key
document key
Definition: result.hxx:122
uint32_t rc
return code for operation
Definition: result.hxx:115
boost::optional< nlohmann::json > value
content of document
Definition: result.hxx:124
uint64_t cas
CAS for document, if any.
Definition: result.hxx:117
std::vector< subdoc_result > values
results of subdoc spec operations
Definition: result.hxx:126
Result of a subdoc operation.
Definition: result.hxx:36