couchbase 3.4.1 → 3.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +2 -0
  4. data/ext/couchbase/cmake/ThirdPartyDependencies.cmake +4 -0
  5. data/ext/couchbase/core/cluster_options.hxx +0 -1
  6. data/ext/couchbase/core/config_profile.cxx +23 -1
  7. data/ext/couchbase/core/config_profile.hxx +2 -12
  8. data/ext/couchbase/core/impl/analytics.cxx +236 -0
  9. data/ext/couchbase/core/impl/cluster.cxx +0 -1
  10. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +5 -3
  11. data/ext/couchbase/core/impl/query.cxx +5 -5
  12. data/ext/couchbase/core/io/dns_client.cxx +225 -0
  13. data/ext/couchbase/core/io/dns_client.hxx +19 -188
  14. data/ext/couchbase/core/transactions/active_transaction_record.hxx +2 -2
  15. data/ext/couchbase/core/transactions/attempt_context_impl.cxx +3 -0
  16. data/ext/couchbase/core/transactions/attempt_context_impl.hxx +1 -1
  17. data/ext/couchbase/core/transactions/internal/transaction_context.hxx +12 -12
  18. data/ext/couchbase/core/transactions/internal/transactions_cleanup.hxx +7 -1
  19. data/ext/couchbase/core/transactions/transaction_context.cxx +1 -0
  20. data/ext/couchbase/core/transactions/transactions_cleanup.cxx +144 -155
  21. data/ext/couchbase/core/utils/connection_string.cxx +10 -3
  22. data/ext/couchbase/core/utils/connection_string.hxx +3 -3
  23. data/ext/couchbase/couchbase/analytics_error_context.hxx +143 -0
  24. data/ext/couchbase/couchbase/analytics_meta_data.hxx +155 -0
  25. data/ext/couchbase/couchbase/analytics_metrics.hxx +163 -0
  26. data/ext/couchbase/couchbase/analytics_options.hxx +359 -0
  27. data/ext/couchbase/couchbase/analytics_result.hxx +102 -0
  28. data/ext/couchbase/couchbase/analytics_scan_consistency.hxx +46 -0
  29. data/ext/couchbase/couchbase/analytics_status.hxx +41 -0
  30. data/ext/couchbase/couchbase/analytics_warning.hxx +85 -0
  31. data/ext/couchbase/couchbase/cluster.hxx +33 -0
  32. data/ext/couchbase/couchbase/fmt/analytics_status.hxx +76 -0
  33. data/ext/couchbase/couchbase/query_options.hxx +0 -1
  34. data/ext/couchbase/couchbase/scope.hxx +33 -0
  35. data/ext/couchbase/couchbase/transactions/attempt_context.hxx +1 -1
  36. data/ext/couchbase/test/CMakeLists.txt +1 -2
  37. data/ext/couchbase/test/test_helper.hxx +1 -1
  38. data/ext/couchbase/test/test_integration_analytics.cxx +289 -13
  39. data/ext/couchbase/test/test_integration_crud.cxx +8 -1
  40. data/ext/couchbase/test/test_integration_examples.cxx +41 -0
  41. data/ext/couchbase/test/test_integration_management.cxx +15 -3
  42. data/ext/couchbase/test/test_integration_search.cxx +601 -0
  43. data/ext/couchbase/test/test_transaction_transaction_simple.cxx +73 -0
  44. data/ext/couchbase/test/test_unit_config_profiles.cxx +12 -12
  45. data/ext/couchbase/test/test_unit_connection_string.cxx +35 -0
  46. data/ext/couchbase/third_party/snappy/CMakeLists.txt +150 -27
  47. data/ext/couchbase/third_party/snappy/cmake/config.h.in +28 -24
  48. data/ext/couchbase/third_party/snappy/snappy-internal.h +189 -25
  49. data/ext/couchbase/third_party/snappy/snappy-sinksource.cc +26 -9
  50. data/ext/couchbase/third_party/snappy/snappy-sinksource.h +11 -11
  51. data/ext/couchbase/third_party/snappy/snappy-stubs-internal.cc +1 -1
  52. data/ext/couchbase/third_party/snappy/snappy-stubs-internal.h +227 -308
  53. data/ext/couchbase/third_party/snappy/snappy-stubs-public.h.in +0 -11
  54. data/ext/couchbase/third_party/snappy/snappy.cc +1176 -410
  55. data/ext/couchbase/third_party/snappy/snappy.h +19 -4
  56. data/ext/couchbase.cxx +27 -6
  57. data/ext/revisions.rb +3 -3
  58. data/lib/couchbase/cluster.rb +13 -9
  59. data/lib/couchbase/cluster_registry.rb +7 -2
  60. data/lib/couchbase/configuration.rb +3 -4
  61. data/lib/couchbase/options.rb +85 -2
  62. data/lib/couchbase/search_options.rb +158 -240
  63. data/lib/couchbase/version.rb +1 -1
  64. metadata +17 -6
  65. data/ext/couchbase/core/CMakeLists.txt +0 -0
@@ -0,0 +1,155 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-Present Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <couchbase/analytics_metrics.hxx>
21
+ #include <couchbase/analytics_status.hxx>
22
+ #include <couchbase/analytics_warning.hxx>
23
+ #include <couchbase/codec/json_transcoder.hxx>
24
+
25
+ #include <cinttypes>
26
+ #include <optional>
27
+ #include <vector>
28
+
29
+ namespace couchbase
30
+ {
31
+
32
+ /**
33
+ * Stores any non-rows results related to the execution of a particular Analytics query.
34
+ *
35
+ * @since 1.0.0
36
+ * @committed
37
+ */
38
+ class analytics_meta_data
39
+ {
40
+ public:
41
+ /**
42
+ * @since 1.0.0
43
+ * @internal
44
+ */
45
+ analytics_meta_data() = default;
46
+
47
+ /**
48
+ * @since 1.0.0
49
+ * @volatile
50
+ */
51
+ analytics_meta_data(std::string request_id,
52
+ std::string client_context_id,
53
+ analytics_status status,
54
+ std::vector<analytics_warning> warnings,
55
+ analytics_metrics metrics,
56
+ std::optional<codec::binary> signature)
57
+ : request_id_{ std::move(request_id) }
58
+ , client_context_id_{ std::move(client_context_id) }
59
+ , status_{ status }
60
+ , warnings_{ std::move(warnings) }
61
+ , metrics_{ std::move(metrics) }
62
+ , signature_{ std::move(signature) }
63
+ {
64
+ }
65
+
66
+ /**
67
+ * Returns the request identifier string of the query request
68
+ *
69
+ * @return The request identifier string
70
+ *
71
+ * @since 1.0.0
72
+ * @committed
73
+ */
74
+ [[nodiscard]] auto request_id() const -> const std::string&
75
+ {
76
+ return request_id_;
77
+ }
78
+
79
+ /**
80
+ * Returns the client context identifier string set on the query request.
81
+ *
82
+ * @return client context identifier
83
+ *
84
+ * @since 1.0.0
85
+ * @committed
86
+ */
87
+ [[nodiscard]] auto client_context_id() const -> const std::string&
88
+ {
89
+ return client_context_id_;
90
+ }
91
+
92
+ /**
93
+ * Returns the raw query execution status as returned by the query engine
94
+ *
95
+ * @return query execution status
96
+ *
97
+ * @since 1.0.0
98
+ * @committed
99
+ */
100
+ [[nodiscard]] auto status() const -> analytics_status
101
+ {
102
+ return status_;
103
+ }
104
+
105
+ /**
106
+ * Returns any warnings returned by the analytics engine.
107
+ *
108
+ * It returns an empty vector if no warnings were returned.
109
+ *
110
+ * @return vector of the reported warnings.
111
+ *
112
+ * @since 1.0.0
113
+ * @committed
114
+ */
115
+ [[nodiscard]] auto warnings() const -> const std::vector<analytics_warning>&
116
+ {
117
+ return warnings_;
118
+ }
119
+
120
+ /**
121
+ * Returns the {@link analytics_metrics} as returned by the analytics engine if enabled.
122
+ *
123
+ * @return metrics
124
+ *
125
+ * @since 1.0.0
126
+ * @committed
127
+ */
128
+ [[nodiscard]] auto metrics() const -> const analytics_metrics&
129
+ {
130
+ return metrics_;
131
+ }
132
+
133
+ /**
134
+ * Returns the signature as returned by the analytics engine.
135
+ *
136
+ * @return optional byte string containing JSON encoded signature
137
+ *
138
+ * @since 1.0.0
139
+ * @committed
140
+ */
141
+ [[nodiscard]] auto signature() const -> const std::optional<codec::binary>&
142
+ {
143
+ return signature_;
144
+ }
145
+
146
+ private:
147
+ std::string request_id_{};
148
+ std::string client_context_id_{};
149
+ analytics_status status_{};
150
+ std::vector<analytics_warning> warnings_{};
151
+ analytics_metrics metrics_{};
152
+ std::optional<codec::binary> signature_{};
153
+ };
154
+
155
+ } // namespace couchbase
@@ -0,0 +1,163 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-Present Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <chrono>
21
+ #include <cinttypes>
22
+
23
+ namespace couchbase
24
+ {
25
+
26
+ /**
27
+ * Analytics Metrics contains the query result metrics containing counts and timings
28
+ *
29
+ * @since 1.0.0
30
+ * @committed
31
+ */
32
+ class analytics_metrics
33
+ {
34
+ public:
35
+ /**
36
+ * @since 1.0.0
37
+ * @internal
38
+ */
39
+ analytics_metrics() = default;
40
+
41
+ /**
42
+ * @since 1.0.0
43
+ * @volatile
44
+ */
45
+ analytics_metrics(std::chrono::nanoseconds elapsed_time,
46
+ std::chrono::nanoseconds execution_time,
47
+ std::uint64_t result_count,
48
+ std::uint64_t result_size,
49
+ std::uint64_t processed_objects,
50
+ std::uint64_t error_count,
51
+ std::uint64_t warning_count)
52
+ : elapsed_time_{ elapsed_time }
53
+ , execution_time_{ execution_time }
54
+ , result_count_{ result_count }
55
+ , result_size_{ result_size }
56
+ , processed_objects_{ processed_objects }
57
+ , error_count_{ error_count }
58
+ , warning_count_{ warning_count }
59
+ {
60
+ }
61
+
62
+ /**
63
+ * The total time taken for the request, that is the time from when the request was received until the results were returned.
64
+ *
65
+ * @return total time duration
66
+ *
67
+ * @since 1.0.0
68
+ * @committed
69
+ */
70
+ [[nodiscard]] auto elapsed_time() const -> std::chrono::nanoseconds
71
+ {
72
+ return elapsed_time_;
73
+ }
74
+
75
+ /**
76
+ * The time taken for the execution of the request, that is the time from when query execution started until the results were returned.
77
+ *
78
+ * @return the execution time duration
79
+ *
80
+ * @since 1.0.0
81
+ * @committed
82
+ */
83
+ [[nodiscard]] auto execution_time() const -> std::chrono::nanoseconds
84
+ {
85
+ return execution_time_;
86
+ }
87
+
88
+ /**
89
+ * The total number of objects in the results.
90
+ *
91
+ * @return number of results
92
+ *
93
+ * @since 1.0.0
94
+ * @committed
95
+ */
96
+ [[nodiscard]] auto result_count() const -> std::uint64_t
97
+ {
98
+ return result_count_;
99
+ }
100
+
101
+ /**
102
+ * The total number of bytes in the results
103
+ *
104
+ * @return number of bytes
105
+ *
106
+ * @since 1.0.0
107
+ * @committed
108
+ */
109
+ [[nodiscard]] auto result_size() const -> std::uint64_t
110
+ {
111
+ return result_size_;
112
+ }
113
+
114
+ /**
115
+ * The number of processed objects for the request.
116
+ *
117
+ * @return number of objects
118
+ *
119
+ * @since 1.0.0
120
+ * @committed
121
+ */
122
+ [[nodiscard]] auto processed_objects() const -> std::uint64_t
123
+ {
124
+ return processed_objects_;
125
+ }
126
+
127
+ /**
128
+ * The number of errors that occurred during the request
129
+ *
130
+ * @return number of errors
131
+ *
132
+ * @since 1.0.0
133
+ * @committed
134
+ */
135
+ [[nodiscard]] auto error_count() const -> std::uint64_t
136
+ {
137
+ return error_count_;
138
+ }
139
+
140
+ /**
141
+ * The number of warnings that occurred during the request.
142
+ *
143
+ * @return number of warnings
144
+ *
145
+ * @since 1.0.0
146
+ * @committed
147
+ */
148
+ [[nodiscard]] auto warning_count() const -> std::uint64_t
149
+ {
150
+ return warning_count_;
151
+ }
152
+
153
+ private:
154
+ std::chrono::nanoseconds elapsed_time_{};
155
+ std::chrono::nanoseconds execution_time_{};
156
+ std::uint64_t result_count_{};
157
+ std::uint64_t result_size_{};
158
+ std::uint64_t processed_objects_{};
159
+ std::uint64_t error_count_{};
160
+ std::uint64_t warning_count_{};
161
+ };
162
+
163
+ } // namespace couchbase
@@ -0,0 +1,359 @@
1
+ /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2020-Present Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #pragma once
19
+
20
+ #include <couchbase/analytics_error_context.hxx>
21
+ #include <couchbase/analytics_result.hxx>
22
+ #include <couchbase/analytics_scan_consistency.hxx>
23
+ #include <couchbase/codec/tao_json_serializer.hxx>
24
+ #include <couchbase/common_options.hxx>
25
+ #include <couchbase/mutation_state.hxx>
26
+
27
+ #include <chrono>
28
+ #include <functional>
29
+ #include <memory>
30
+ #include <optional>
31
+
32
+ namespace couchbase
33
+ {
34
+ /**
35
+ * Options for cluster#analytics_query() and scope#analytics_query().
36
+ *
37
+ * @since 1.0.0
38
+ * @committed
39
+ */
40
+ struct analytics_options : public common_options<analytics_options> {
41
+ /**
42
+ * Immutable value object representing consistent options.
43
+ *
44
+ * @since 1.0.0
45
+ * @internal
46
+ */
47
+ struct built : public common_options<analytics_options>::built {
48
+ std::optional<std::string> client_context_id;
49
+ const bool priority;
50
+ const bool readonly;
51
+ std::optional<analytics_scan_consistency> scan_consistency;
52
+ std::optional<std::chrono::milliseconds> scan_wait;
53
+ std::vector<mutation_token> mutation_state;
54
+ std::vector<codec::binary> positional_parameters;
55
+ std::map<std::string, codec::binary, std::less<>> named_parameters;
56
+ std::map<std::string, codec::binary, std::less<>> raw;
57
+ };
58
+
59
+ /**
60
+ * Validates options and returns them as an immutable value.
61
+ *
62
+ * @return consistent options as an immutable value
63
+ *
64
+ * @exception std::system_error with code errc::common::invalid_argument if the options are not valid
65
+ *
66
+ * @since 1.0.0
67
+ * @internal
68
+ */
69
+ [[nodiscard]] auto build() const -> built
70
+ {
71
+ return {
72
+ build_common_options(), client_context_id_, priority_, readonly_, scan_consistency_, scan_wait_,
73
+ mutation_state_, positional_parameters_, named_parameters_, raw_,
74
+ };
75
+ }
76
+
77
+ /**
78
+ * Allows to give certain requests higher priority than others.
79
+ *
80
+ * @param prioritized if set to true this query will be treated with a higher priority by the service.
81
+ * @return this options builder for chaining purposes.
82
+ *
83
+ * @since 1.0.0
84
+ * @committed
85
+ */
86
+ auto priority(bool prioritized) -> analytics_options&
87
+ {
88
+ priority_ = prioritized;
89
+ return self();
90
+ }
91
+
92
+ /**
93
+ * Allows explicitly marking a query as being readonly and not mutating and documents on the server side.
94
+ *
95
+ * In addition to providing some security in that you are not accidentally modifying data, setting this flag to true also helps the
96
+ * client to more proactively retry and re-dispatch a query since then it can be sure it is idempotent. As a result, if your query is
97
+ * readonly then it is a good idea to set this flag.
98
+ *
99
+ * @param readonly true if readonly should be set, false is the default and will use the server side default.
100
+ * @return this options builder for chaining purposes.
101
+ *
102
+ * @since 1.0.0
103
+ * @committed
104
+ */
105
+ auto readonly(bool readonly) -> analytics_options&
106
+ {
107
+ readonly_ = readonly;
108
+ return self();
109
+ }
110
+
111
+ /**
112
+ * Allows customizing how long the query engine is willing to wait until the index catches up to whatever scan
113
+ * consistency is asked for in this query.
114
+ *
115
+ * @note that if {@link analytics_scan_consistency::not_bounded} is used, this method doesn't do anything at all. If no value is
116
+ * provided to this method, the server default is used.
117
+ *
118
+ * @param wait the maximum duration the query engine is willing to wait before failing.
119
+ * @return this options builder for chaining purposes.
120
+ *
121
+ * @since 1.0.0
122
+ * @committed
123
+ */
124
+ auto scan_wait(std::chrono::milliseconds wait) -> analytics_options&
125
+ {
126
+ if (scan_consistency_ == analytics_scan_consistency::not_bounded) {
127
+ scan_wait_.reset();
128
+ } else {
129
+ scan_wait_ = wait;
130
+ }
131
+ return self();
132
+ }
133
+
134
+ /**
135
+ * Supports providing a custom client context ID for this query.
136
+ *
137
+ * If no client context ID is provided by the user, a UUID is generated and sent automatically so by default it is always possible to
138
+ * identify a query when debugging.
139
+ *
140
+ * @param client_context_id the client context ID
141
+ * @return this options builder for chaining purposes.
142
+ *
143
+ * @since 1.0.0
144
+ * @committed
145
+ */
146
+ auto client_context_id(std::string client_context_id) -> analytics_options&
147
+ {
148
+ if (client_context_id.empty()) {
149
+ client_context_id_.reset();
150
+ } else {
151
+ client_context_id_ = std::move(client_context_id);
152
+ }
153
+ return self();
154
+ }
155
+
156
+ /**
157
+ * Customizes the consistency guarantees for this query.
158
+ *
159
+ * Tuning the scan consistency allows to trade data "freshness" for latency and vice versa. By default
160
+ * {@link analytics_scan_consistency::not_bounded} is used, which means that the server returns the data it has in the index right away.
161
+ * This is fast, but might not include the most recent mutations. If you want to include all the mutations up to the point of the query,
162
+ * use {@link analytics_scan_consistency::request_plus}.
163
+ *
164
+ * Note that you cannot use this method and {@link #consistent_with(const mutation_state&)} at the same time, since they are mutually
165
+ * exclusive. As a rule of thumb, if you only care to be consistent with the mutation you just wrote on the same thread/app, use
166
+ * {@link #consistent_with(const mutation_state&)}. If you need "global" scan consistency, use
167
+ * {@link analytics_scan_consistency::request_plus} on this method.
168
+ *
169
+ * @param scan_consistency the index scan consistency to be used for this query
170
+ * @return this options builder for chaining purposes.
171
+ *
172
+ * @since 1.0.0
173
+ * @committed
174
+ */
175
+ auto scan_consistency(analytics_scan_consistency scan_consistency) -> analytics_options&
176
+ {
177
+ scan_consistency_ = scan_consistency;
178
+ mutation_state_.clear();
179
+ return self();
180
+ }
181
+
182
+ /**
183
+ * Sets the {@link mutation_token}s this query should be consistent with.
184
+ *
185
+ * These mutation tokens are returned from mutations (i.e. as part of a {@link mutation_result}) and if you want your
186
+ * N1QL query to include those you need to pass the mutation tokens into a {@link mutation_state}.
187
+ *
188
+ * Note that you cannot use this method and {@link #scan_consistency(analytics_scan_consistency)} at the same time, since
189
+ * they are mutually exclusive. As a rule of thumb, if you only care to be consistent with the mutation you just wrote
190
+ * on the same thread/app, use this method. If you need "global" scan consistency, use
191
+ * {@link analytics_scan_consistency#request_plus} on {@link #scan_consistency(analytics_scan_consistency)}.
192
+ *
193
+ * @param state the mutation state containing the mutation tokens.
194
+ * @return this options builder for chaining purposes.
195
+ *
196
+ * @since 1.0.0
197
+ * @committed
198
+ */
199
+ auto consistent_with(const mutation_state& state) -> analytics_options&
200
+ {
201
+ mutation_state_ = state.tokens();
202
+ scan_consistency_.reset();
203
+ return self();
204
+ }
205
+
206
+ /**
207
+ *
208
+ * @tparam Value
209
+ * @param name
210
+ * @param value
211
+ * @return this options builder for chaining purposes.
212
+ *
213
+ * @since 1.0.0
214
+ * @committed
215
+ */
216
+ template<typename Value>
217
+ auto raw(std::string name, const Value& value) -> analytics_options&
218
+ {
219
+ raw_[std::move(name)] = std::move(codec::tao_json_serializer::serialize(value));
220
+ return self();
221
+ }
222
+
223
+ /**
224
+ * Set list of positional parameters for a query.
225
+ *
226
+ * @tparam Parameters types for the parameters
227
+ * @param parameters the sequence of positional parameters. Each entry will be encoded into JSON.
228
+ * @return this options builder for chaining purposes.
229
+ *
230
+ * @since 1.0.0
231
+ * @committed
232
+ */
233
+ template<typename... Parameters>
234
+ auto positional_parameters(const Parameters&... parameters) -> analytics_options&
235
+ {
236
+ named_parameters_.clear();
237
+ positional_parameters_.clear();
238
+ encode_positional_parameters(parameters...);
239
+ return self();
240
+ }
241
+
242
+ /**
243
+ * Set list of named parameters for a query.
244
+ *
245
+ * @tparam Parameters types for the parameter pairs
246
+ * @param parameters the sequence of name-value pairs. Each value will be encoded into JSON.
247
+ * @return this options builder for chaining purposes.
248
+ *
249
+ * @since 1.0.0
250
+ * @committed
251
+ */
252
+ template<typename... Parameters>
253
+ auto named_parameters(const Parameters&... parameters) -> analytics_options&
254
+ {
255
+ named_parameters_.clear();
256
+ positional_parameters_.clear();
257
+ encode_named_parameters(parameters...);
258
+ return self();
259
+ }
260
+
261
+ /**
262
+ * Set map of raw options for a query.
263
+ *
264
+ * This function expects that all parameters encoded into pairs containing mapping names of the parameter to valid JSON values encoded
265
+ * as string.
266
+ *
267
+ * @note This function is low-level, and instead @ref raw() should be considered.
268
+ *
269
+ * @param options mapping of pairs, where each entry contains string with valid JSON value.
270
+ * @return this options builder for chaining purposes.
271
+ *
272
+ * @since 1.0.0
273
+ * @uncommitted
274
+ */
275
+ auto encoded_raw_options(std::map<std::string, codec::binary, std::less<>> options) -> analytics_options&
276
+ {
277
+ raw_ = std::move(options);
278
+ return self();
279
+ }
280
+
281
+ /**
282
+ * Set list of positional parameters for a query.
283
+ *
284
+ * This function expects that all parameters encoded into byte strings containing valid JSON values.
285
+ *
286
+ * @note This function is low-level, and instead @ref positional_parameters() should be considered.
287
+ *
288
+ * @param parameters vector of binaries, where each entry contains string with valid JSON value.
289
+ * @return this options builder for chaining purposes.
290
+ *
291
+ * @since 1.0.0
292
+ * @uncommitted
293
+ */
294
+ auto encoded_positional_parameters(std::vector<codec::binary> parameters) -> analytics_options&
295
+ {
296
+ named_parameters_.clear();
297
+ positional_parameters_ = std::move(parameters);
298
+ return self();
299
+ }
300
+
301
+ /**
302
+ * Set map of named parameters for a query.
303
+ *
304
+ * This function expects that all parameters encoded into pairs containing mapping names of the parameter to valid JSON values encoded
305
+ * as string.
306
+ *
307
+ * @note This function is low-level, and instead @ref named_parameters() should be considered.
308
+ *
309
+ * @param parameters mapping of pairs, where each entry contains string with valid JSON value.
310
+ * @return this options builder for chaining purposes.
311
+ *
312
+ * @since 1.0.0
313
+ * @uncommitted
314
+ */
315
+ auto encoded_named_parameters(std::map<std::string, codec::binary, std::less<>> parameters) -> analytics_options&
316
+ {
317
+ named_parameters_ = std::move(parameters);
318
+ positional_parameters_.clear();
319
+ return self();
320
+ }
321
+
322
+ private:
323
+ template<typename Parameter, typename... Rest>
324
+ void encode_positional_parameters(const Parameter& parameter, Rest... args)
325
+ {
326
+ positional_parameters_.emplace_back(std::move(codec::tao_json_serializer::serialize(parameter)));
327
+ if constexpr (sizeof...(args) > 0) {
328
+ encode_positional_parameters(args...);
329
+ }
330
+ }
331
+
332
+ template<typename Name, typename Parameter, typename... Rest>
333
+ void encode_named_parameters(const std::pair<Name, Parameter>& parameter, Rest... args)
334
+ {
335
+ named_parameters_[parameter.first] = std::move(codec::tao_json_serializer::serialize(parameter.second));
336
+ if constexpr (sizeof...(args) > 0) {
337
+ encode_named_parameters(args...);
338
+ }
339
+ }
340
+
341
+ bool priority_{ true };
342
+ bool readonly_{ false };
343
+ std::optional<std::string> client_context_id_{};
344
+ std::optional<std::chrono::milliseconds> scan_wait_{};
345
+ std::optional<analytics_scan_consistency> scan_consistency_{};
346
+ std::vector<mutation_token> mutation_state_{};
347
+ std::vector<codec::binary> positional_parameters_{};
348
+ std::map<std::string, codec::binary, std::less<>> raw_{};
349
+ std::map<std::string, codec::binary, std::less<>> named_parameters_{};
350
+ };
351
+
352
+ /**
353
+ * The signature for the handler of the @ref cluster#analytics_query() and @ref scope#analytics_query() operations
354
+ *
355
+ * @since 1.0.0
356
+ * @uncommitted
357
+ */
358
+ using analytics_handler = std::function<void(couchbase::analytics_error_context, analytics_result)>;
359
+ } // namespace couchbase