Couchbase C++ SDK 1.1.0 (rev. effbd6e)
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
27
28namespace couchbase
29{
30class collection;
31class scope;
32
33namespace transactions
34{
37using async_err_handler = std::function<void(error)>;
38
48{
49public:
50 virtual ~async_attempt_context() = default;
54 auto operator=(async_attempt_context&&) -> async_attempt_context& = default;
55 auto operator=(const async_attempt_context&) -> async_attempt_context& = default;
56
68 virtual void get(const collection& coll, std::string id, async_result_handler&& handler) = 0;
69
92 const std::string& id,
93 async_result_handler&& handler) = 0;
94
95 virtual void get_multi(
96 const std::vector<transaction_get_multi_spec>& specs,
97 const transaction_get_multi_options& options,
98 std::function<void(error, std::optional<transaction_get_multi_result>)>&& cb) = 0;
99
103 std::function<void(
104 error,
106
117 virtual void remove(transaction_get_result doc, async_err_handler&& handler) = 0;
118
133 template<typename Transcoder = codec::default_json_transcoder,
134 typename Document,
135 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
136 void insert(const collection& coll,
137 std::string id,
138 Document&& content,
139 async_result_handler&& handler)
140 {
141 return insert_raw(
142 coll, id, Transcoder::encode(std::forward<Document>(content)), std::move(handler));
143 }
144
157 template<typename Transcoder = codec::default_json_transcoder,
158 typename Document,
159 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
160 void replace(transaction_get_result doc, Document&& content, async_result_handler&& handler)
161 {
162 return replace_raw(
163 std::move(doc), Transcoder::encode(std::forward<Document>(content)), std::move(handler));
164 }
165
176 void query(const scope& scope,
177 std::string statement,
179 async_query_handler&& handler);
180
190 void query(std::string statement, transaction_query_options opts, async_query_handler&& handler)
191 {
192 return query(std::move(statement), std::move(opts), {}, std::move(handler));
193 };
194
202 void query(std::string statement, async_query_handler&& handler)
203 {
204 return query(std::move(statement), {}, std::move(handler));
205 }
206
207protected:
209 virtual void insert_raw(const collection& coll,
210 std::string id,
211 codec::encoded_value content,
212 async_result_handler&& handler) = 0;
214 virtual void replace_raw(transaction_get_result doc,
215 codec::encoded_value content,
216 async_result_handler&& handler) = 0;
218 virtual void query(std::string statement,
220 std::optional<std::string> query_context,
221 async_query_handler&&) = 0;
222};
223} // namespace transactions
224} // 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
async_attempt_context(async_attempt_context &&) noexcept=default
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:136
void query(std::string statement, transaction_query_options opts, async_query_handler &&handler)
Perform a query.
Definition async_attempt_context.hxx:190
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_multi_replicas_from_preferred_server_group(const std::vector< transaction_get_multi_replicas_from_preferred_server_group_spec > &specs, const transaction_get_multi_replicas_from_preferred_server_group_options &options, std::function< void(error, std::optional< transaction_get_multi_replicas_from_preferred_server_group_result >)> &&cb)=0
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.
virtual void get_multi(const std::vector< transaction_get_multi_spec > &specs, const transaction_get_multi_options &options, std::function< void(error, std::optional< transaction_get_multi_result >)> &&cb)=0
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:160
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:202
Definition transaction_get_multi_options.hxx:30
Definition transaction_get_multi_replicas_from_preferred_server_group_options.hxx:30
Definition transaction_get_multi_replicas_from_preferred_server_group_result.hxx:36
Definition transaction_get_multi_replicas_from_preferred_server_group_spec.hxx:31
Definition transaction_get_multi_result.hxx:33
Definition transaction_get_multi_spec.hxx:31
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
Definition analytics_options.hxx:35
json_transcoder< tao_json_serializer > default_json_transcoder
Definition default_json_transcoder.hxx:28
Definition transactions.hxx:28
std::function< void(error, transaction_get_result)> async_result_handler
Definition async_attempt_context.hxx:35
std::function< void(error, transaction_query_result)> async_query_handler
Definition async_attempt_context.hxx:36
std::function< void(error)> async_err_handler
Definition async_attempt_context.hxx:37
Represents a single item from the result of scan()
Definition allow_querying_search_index_options.hxx:28
@ query
The Query service (SQL++)
Definition service_type.hxx:31
Definition encoded_value.hxx:27