Couchbase C++ SDK 1.0.1 (rev. 58d46d7)
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
74 const std::string& id,
75 async_result_handler&& handler) = 0;
76
87 virtual void remove(transaction_get_result doc, async_err_handler&& handler) = 0;
88
103 template<typename Transcoder = codec::default_json_transcoder,
104 typename Document,
105 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
106 void insert(const collection& coll,
107 std::string id,
108 Document&& content,
109 async_result_handler&& handler)
110 {
111 return insert_raw(coll, id, Transcoder::encode(content), std::move(handler));
112 }
126 template<typename Transcoder = codec::default_json_transcoder,
127 typename Document,
128 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
129 void replace(transaction_get_result doc, Document&& content, async_result_handler&& handler)
130 {
131 return replace_raw(std::move(doc), Transcoder::encode(content), std::move(handler));
132 }
144 void query(const scope& scope,
145 std::string statement,
147 async_query_handler&& handler);
148
158 void query(std::string statement, transaction_query_options opts, async_query_handler&& handler)
159 {
160 return query(std::move(statement), std::move(opts), {}, std::move(handler));
161 };
170 void query(std::string statement, async_query_handler&& handler)
171 {
172 return query(std::move(statement), {}, std::move(handler));
173 }
174
175 virtual ~async_attempt_context() = default;
176
177protected:
179 virtual void insert_raw(const collection& coll,
180 std::string id,
181 codec::encoded_value content,
182 async_result_handler&& handler) = 0;
184 virtual void replace_raw(transaction_get_result doc,
185 codec::encoded_value content,
186 async_result_handler&& handler) = 0;
188 virtual void query(std::string statement,
190 std::optional<std::string> query_context,
191 async_query_handler&&) = 0;
192};
193} // namespace transactions
194} // 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:106
void query(std::string statement, transaction_query_options opts, async_query_handler &&handler)
Perform a query.
Definition async_attempt_context.hxx:158
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:129
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:170
Definition transaction_get_result.hxx:39
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