Couchbase C++ SDK 1.0.2 (rev. 51f4775)
Loading...
Searching...
No Matches
async_attempt_context.hxx
Go to the documentation of this file.
1/*
2 * Copyright 2021-Present 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#pragma once
17
21
22namespace couchbase
23{
24class collection;
25class scope;
26
27namespace transactions
28{
31using async_err_handler = std::function<void(error)>;
32
42{
43
44public:
56 virtual void get(const collection& coll, std::string id, async_result_handler&& handler) = 0;
57
80 const std::string& id,
81 async_result_handler&& handler) = 0;
82
93 virtual void remove(transaction_get_result doc, async_err_handler&& handler) = 0;
94
109 template<typename Transcoder = codec::default_json_transcoder,
110 typename Document,
111 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
112 void insert(const collection& coll,
113 std::string id,
114 Document&& content,
115 async_result_handler&& handler)
116 {
117 return insert_raw(coll, id, Transcoder::encode(content), std::move(handler));
118 }
132 template<typename Transcoder = codec::default_json_transcoder,
133 typename Document,
134 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
135 void replace(transaction_get_result doc, Document&& content, async_result_handler&& handler)
136 {
137 return replace_raw(std::move(doc), Transcoder::encode(content), std::move(handler));
138 }
150 void query(const scope& scope,
151 std::string statement,
153 async_query_handler&& handler);
154
164 void query(std::string statement, transaction_query_options opts, async_query_handler&& handler)
165 {
166 return query(std::move(statement), std::move(opts), {}, std::move(handler));
167 };
176 void query(std::string statement, async_query_handler&& handler)
177 {
178 return query(std::move(statement), {}, std::move(handler));
179 }
180
181 virtual ~async_attempt_context() = default;
182
183protected:
185 virtual void insert_raw(const collection& coll,
186 std::string id,
187 codec::encoded_value content,
188 async_result_handler&& handler) = 0;
190 virtual void replace_raw(transaction_get_result doc,
191 codec::encoded_value content,
192 async_result_handler&& handler) = 0;
194 virtual void query(std::string statement,
196 std::optional<std::string> query_context,
197 async_query_handler&&) = 0;
198};
199} // namespace transactions
200} // namespace couchbase
The collection provides access to all collection APIs.
Definition collection.hxx:70
Definition error.hxx:30
The scope identifies a group of collections and allows high application density as a result.
Definition scope.hxx:47
The async_attempt_context is used for all asynchronous transaction operations.
Definition async_attempt_context.hxx:42
void insert(const collection &coll, std::string id, Document &&content, async_result_handler &&handler)
Insert a document into a collection.
Definition async_attempt_context.hxx:112
void query(std::string statement, transaction_query_options opts, async_query_handler &&handler)
Perform a query.
Definition async_attempt_context.hxx:164
void query(const scope &scope, std::string statement, transaction_query_options opts, async_query_handler &&handler)
Perform a query, within a scope.
virtual void remove(transaction_get_result doc, async_err_handler &&handler)=0
Remove a document from a collection.
virtual void get_replica_from_preferred_server_group(const couchbase::collection &coll, const std::string &id, async_result_handler &&handler)=0
Get a document copy from the selected server group.
void replace(transaction_get_result doc, Document &&content, async_result_handler &&handler)
Replace the contents of a document in a collection.
Definition async_attempt_context.hxx:135
virtual void get(const collection &coll, std::string id, async_result_handler &&handler)=0
Get document from a collection.
void query(std::string statement, async_query_handler &&handler)
Perform a query.
Definition async_attempt_context.hxx:176
The representation of the document in context of distributed transaction.
Definition transaction_get_result.hxx:57
The transaction_query_options are options specific to a query.
Definition transaction_query_options.hxx:35
Transactional queries will return a transaction_query_result.
Definition transaction_query_result.hxx:27
json_transcoder< tao_json_serializer > default_json_transcoder
Definition default_json_transcoder.hxx:28
std::function< void(error, transaction_get_result)> async_result_handler
Definition async_attempt_context.hxx:29
std::function< void(error, transaction_query_result)> async_query_handler
Definition async_attempt_context.hxx:30
std::function< void(error)> async_err_handler
Definition async_attempt_context.hxx:31
Represents a single item from the result of collection::scan()
Definition allow_querying_search_index_options.hxx:28
@ query
The Query service (SQL++)
Definition encoded_value.hxx:27