couchbase 3.4.3 → 3.4.5

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 (179) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/couchbase/CMakeLists.txt +22 -1
  4. data/ext/couchbase/core/bucket.cxx +183 -152
  5. data/ext/couchbase/core/bucket.hxx +17 -4
  6. data/ext/couchbase/core/cluster.hxx +41 -13
  7. data/ext/couchbase/core/cluster_options.hxx +3 -0
  8. data/ext/couchbase/core/crud_component.cxx +51 -22
  9. data/ext/couchbase/core/error_context/key_value.cxx +2 -1
  10. data/ext/couchbase/core/error_context/key_value.hxx +10 -12
  11. data/ext/couchbase/core/impl/build_deferred_query_indexes.cxx +115 -50
  12. data/ext/couchbase/core/impl/cluster.cxx +6 -0
  13. data/ext/couchbase/core/impl/create_bucket.cxx +158 -0
  14. data/ext/couchbase/core/impl/create_collection.cxx +83 -0
  15. data/ext/couchbase/core/impl/create_query_index.cxx +172 -59
  16. data/ext/couchbase/core/impl/create_scope.cxx +69 -0
  17. data/ext/couchbase/core/impl/dns_srv_tracker.cxx +2 -1
  18. data/ext/couchbase/core/impl/drop_bucket.cxx +66 -0
  19. data/ext/couchbase/core/impl/drop_collection.cxx +76 -0
  20. data/ext/couchbase/core/impl/drop_query_index.cxx +138 -59
  21. data/ext/couchbase/core/impl/drop_scope.cxx +68 -0
  22. data/ext/couchbase/core/impl/flush_bucket.cxx +66 -0
  23. data/ext/couchbase/core/impl/get_all_buckets.cxx +178 -0
  24. data/ext/couchbase/core/impl/get_all_query_indexes.cxx +67 -37
  25. data/ext/couchbase/core/impl/get_all_scopes.cxx +94 -0
  26. data/ext/couchbase/core/impl/get_bucket.cxx +168 -0
  27. data/ext/couchbase/core/impl/internal_manager_error_context.cxx +113 -0
  28. data/ext/couchbase/core/impl/internal_manager_error_context.hxx +60 -0
  29. data/ext/couchbase/core/impl/key_value_error_category.cxx +2 -4
  30. data/ext/couchbase/core/impl/key_value_error_context.cxx +98 -0
  31. data/ext/couchbase/core/impl/lookup_in.cxx +1 -0
  32. data/ext/couchbase/core/impl/lookup_in_all_replicas.cxx +178 -0
  33. data/ext/couchbase/core/impl/lookup_in_all_replicas.hxx +80 -0
  34. data/ext/couchbase/core/impl/lookup_in_any_replica.cxx +169 -0
  35. data/ext/couchbase/core/impl/lookup_in_any_replica.hxx +75 -0
  36. data/ext/couchbase/core/impl/lookup_in_replica.cxx +104 -0
  37. data/ext/couchbase/core/impl/lookup_in_replica.hxx +67 -0
  38. data/ext/couchbase/core/impl/manager_error_context.cxx +100 -0
  39. data/ext/couchbase/core/impl/query.cxx +1 -0
  40. data/ext/couchbase/core/impl/query_error_context.cxx +75 -0
  41. data/ext/couchbase/core/impl/update_bucket.cxx +133 -0
  42. data/ext/couchbase/core/impl/update_collection.cxx +83 -0
  43. data/ext/couchbase/core/impl/watch_query_indexes.cxx +53 -29
  44. data/ext/couchbase/core/io/dns_client.cxx +111 -40
  45. data/ext/couchbase/core/io/dns_config.cxx +5 -4
  46. data/ext/couchbase/core/io/http_session.hxx +24 -1
  47. data/ext/couchbase/core/io/mcbp_command.hxx +9 -2
  48. data/ext/couchbase/core/io/mcbp_session.cxx +80 -43
  49. data/ext/couchbase/core/io/mcbp_session.hxx +4 -3
  50. data/ext/couchbase/core/logger/custom_rotating_file_sink.cxx +1 -1
  51. data/ext/couchbase/core/logger/logger.cxx +80 -20
  52. data/ext/couchbase/core/logger/logger.hxx +31 -0
  53. data/ext/couchbase/core/management/bucket_settings.hxx +8 -5
  54. data/ext/couchbase/core/management/bucket_settings_json.hxx +12 -2
  55. data/ext/couchbase/core/meta/features.hxx +42 -0
  56. data/ext/couchbase/core/operations/document_lookup_in.cxx +8 -1
  57. data/ext/couchbase/core/operations/document_lookup_in_all_replicas.hxx +192 -0
  58. data/ext/couchbase/core/operations/document_lookup_in_any_replica.hxx +188 -0
  59. data/ext/couchbase/core/operations/document_query.cxx +11 -0
  60. data/ext/couchbase/core/operations/document_query.hxx +1 -0
  61. data/ext/couchbase/core/operations/management/CMakeLists.txt +1 -0
  62. data/ext/couchbase/core/operations/management/bucket_create.cxx +30 -9
  63. data/ext/couchbase/core/operations/management/bucket_update.cxx +27 -6
  64. data/ext/couchbase/core/operations/management/collection_create.cxx +5 -1
  65. data/ext/couchbase/core/operations/management/collection_create.hxx +1 -0
  66. data/ext/couchbase/core/operations/management/collection_update.cxx +87 -0
  67. data/ext/couchbase/core/operations/management/collection_update.hxx +54 -0
  68. data/ext/couchbase/core/operations/management/collections.hxx +1 -0
  69. data/ext/couchbase/core/operations.hxx +2 -0
  70. data/ext/couchbase/core/origin.cxx +270 -0
  71. data/ext/couchbase/core/origin.hxx +2 -0
  72. data/ext/couchbase/core/protocol/client_response.hxx +1 -0
  73. data/ext/couchbase/core/protocol/cmd_hello.hxx +1 -0
  74. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.cxx +107 -0
  75. data/ext/couchbase/core/protocol/cmd_lookup_in_replica.hxx +137 -0
  76. data/ext/couchbase/core/protocol/hello_feature.hxx +6 -0
  77. data/ext/couchbase/core/protocol/hello_feature_fmt.hxx +3 -0
  78. data/ext/couchbase/core/protocol/status.cxx +2 -2
  79. data/ext/couchbase/core/range_scan_options.cxx +3 -27
  80. data/ext/couchbase/core/range_scan_options.hxx +13 -17
  81. data/ext/couchbase/core/range_scan_orchestrator.cxx +388 -170
  82. data/ext/couchbase/core/range_scan_orchestrator.hxx +13 -2
  83. data/ext/couchbase/core/range_scan_orchestrator_options.hxx +5 -3
  84. data/ext/couchbase/core/scan_options.hxx +0 -19
  85. data/ext/couchbase/core/scan_result.cxx +19 -5
  86. data/ext/couchbase/core/scan_result.hxx +5 -2
  87. data/ext/couchbase/core/timeout_defaults.hxx +3 -4
  88. data/ext/couchbase/core/topology/capabilities.hxx +4 -0
  89. data/ext/couchbase/core/topology/capabilities_fmt.hxx +11 -0
  90. data/ext/couchbase/core/topology/collections_manifest.hxx +2 -0
  91. data/ext/couchbase/core/topology/collections_manifest_fmt.hxx +1 -1
  92. data/ext/couchbase/core/topology/collections_manifest_json.hxx +3 -0
  93. data/ext/couchbase/core/topology/configuration.hxx +20 -0
  94. data/ext/couchbase/core/topology/configuration_json.hxx +8 -1
  95. data/ext/couchbase/core/utils/connection_string.cxx +62 -47
  96. data/ext/couchbase/core/utils/connection_string.hxx +1 -0
  97. data/ext/couchbase/couchbase/analytics_error_context.hxx +1 -1
  98. data/ext/couchbase/couchbase/behavior_options.hxx +19 -2
  99. data/ext/couchbase/couchbase/bucket.hxx +14 -0
  100. data/ext/couchbase/couchbase/bucket_manager.hxx +135 -0
  101. data/ext/couchbase/couchbase/build_query_index_options.hxx +0 -30
  102. data/ext/couchbase/couchbase/cluster.hxx +14 -0
  103. data/ext/couchbase/couchbase/collection.hxx +111 -0
  104. data/ext/couchbase/couchbase/collection_manager.hxx +160 -0
  105. data/ext/couchbase/couchbase/collection_query_index_manager.hxx +7 -48
  106. data/ext/couchbase/couchbase/create_bucket_options.hxx +41 -0
  107. data/ext/couchbase/couchbase/create_collection_options.hxx +44 -0
  108. data/ext/couchbase/couchbase/create_primary_query_index_options.hxx +0 -29
  109. data/ext/couchbase/couchbase/create_query_index_options.hxx +0 -33
  110. data/ext/couchbase/couchbase/create_scope_options.hxx +41 -0
  111. data/ext/couchbase/couchbase/drop_bucket_options.hxx +41 -0
  112. data/ext/couchbase/couchbase/drop_collection_options.hxx +41 -0
  113. data/ext/couchbase/couchbase/drop_primary_query_index_options.hxx +0 -30
  114. data/ext/couchbase/couchbase/drop_query_index_options.hxx +0 -31
  115. data/ext/couchbase/couchbase/drop_scope_options.hxx +41 -0
  116. data/ext/couchbase/couchbase/error_codes.hxx +1 -2
  117. data/ext/couchbase/couchbase/error_context.hxx +10 -2
  118. data/ext/couchbase/couchbase/flush_bucket_options.hxx +41 -0
  119. data/ext/couchbase/{core/topology/error_map_fmt.hxx → couchbase/fmt/key_value_error_map_attribute.hxx} +21 -21
  120. data/ext/couchbase/couchbase/get_all_buckets_options.hxx +44 -0
  121. data/ext/couchbase/couchbase/get_all_query_indexes_options.hxx +0 -30
  122. data/ext/couchbase/couchbase/get_all_scopes_options.hxx +44 -0
  123. data/ext/couchbase/couchbase/get_and_lock_options.hxx +2 -2
  124. data/ext/couchbase/couchbase/get_and_touch_options.hxx +2 -2
  125. data/ext/couchbase/couchbase/get_bucket_options.hxx +43 -0
  126. data/ext/couchbase/couchbase/get_options.hxx +2 -2
  127. data/ext/couchbase/couchbase/insert_options.hxx +3 -3
  128. data/ext/couchbase/couchbase/key_value_error_context.hxx +7 -2
  129. data/ext/couchbase/couchbase/lookup_in_all_replicas_options.hxx +109 -0
  130. data/ext/couchbase/couchbase/lookup_in_any_replica_options.hxx +101 -0
  131. data/ext/couchbase/couchbase/lookup_in_options.hxx +2 -2
  132. data/ext/couchbase/couchbase/lookup_in_replica_result.hxx +74 -0
  133. data/ext/couchbase/couchbase/lookup_in_result.hxx +26 -0
  134. data/ext/couchbase/couchbase/management/bucket_settings.hxx +119 -0
  135. data/ext/couchbase/couchbase/management/collection_spec.hxx +29 -0
  136. data/ext/couchbase/couchbase/management/scope_spec.hxx +29 -0
  137. data/ext/couchbase/couchbase/manager_error_context.hxx +29 -53
  138. data/ext/couchbase/couchbase/mutate_in_options.hxx +2 -2
  139. data/ext/couchbase/couchbase/query_error_context.hxx +3 -1
  140. data/ext/couchbase/couchbase/query_index_manager.hxx +16 -83
  141. data/ext/couchbase/couchbase/query_options.hxx +18 -0
  142. data/ext/couchbase/couchbase/remove_options.hxx +2 -2
  143. data/ext/couchbase/couchbase/replace_options.hxx +3 -3
  144. data/ext/couchbase/couchbase/security_options.hxx +15 -0
  145. data/ext/couchbase/couchbase/subdocument_error_context.hxx +4 -2
  146. data/ext/couchbase/couchbase/touch_options.hxx +2 -2
  147. data/ext/couchbase/couchbase/unlock_options.hxx +2 -2
  148. data/ext/couchbase/couchbase/update_bucket_options.hxx +41 -0
  149. data/ext/couchbase/couchbase/update_collection_options.hxx +44 -0
  150. data/ext/couchbase/couchbase/upsert_options.hxx +3 -3
  151. data/ext/couchbase/couchbase/watch_query_indexes_options.hxx +0 -31
  152. data/ext/couchbase/test/CMakeLists.txt +1 -0
  153. data/ext/couchbase/test/test_integration_collections.cxx +6 -0
  154. data/ext/couchbase/test/test_integration_crud.cxx +5 -0
  155. data/ext/couchbase/test/test_integration_examples.cxx +137 -1
  156. data/ext/couchbase/test/test_integration_management.cxx +1009 -309
  157. data/ext/couchbase/test/test_integration_query.cxx +19 -7
  158. data/ext/couchbase/test/test_integration_range_scan.cxx +351 -112
  159. data/ext/couchbase/test/test_integration_search.cxx +10 -1
  160. data/ext/couchbase/test/test_integration_subdoc.cxx +721 -7
  161. data/ext/couchbase/test/test_transaction_public_async_api.cxx +13 -12
  162. data/ext/couchbase/test/test_transaction_public_blocking_api.cxx +27 -21
  163. data/ext/couchbase/test/test_unit_connection_string.cxx +29 -0
  164. data/ext/couchbase/test/test_unit_query.cxx +75 -0
  165. data/ext/couchbase.cxx +735 -60
  166. data/ext/revisions.rb +3 -3
  167. data/lib/couchbase/cluster.rb +1 -1
  168. data/lib/couchbase/collection.rb +108 -0
  169. data/lib/couchbase/collection_options.rb +100 -1
  170. data/lib/couchbase/errors.rb +5 -0
  171. data/lib/couchbase/key_value_scan.rb +125 -0
  172. data/lib/couchbase/management/bucket_manager.rb +22 -15
  173. data/lib/couchbase/management/collection_manager.rb +158 -9
  174. data/lib/couchbase/options.rb +151 -0
  175. data/lib/couchbase/scope.rb +1 -1
  176. data/lib/couchbase/utils/time.rb +14 -1
  177. data/lib/couchbase/version.rb +1 -1
  178. metadata +59 -8
  179. data/ext/couchbase/core/impl/collection_query_index_manager.cxx +0 -93
@@ -60,6 +60,21 @@ class behavior_options
60
60
  return *this;
61
61
  }
62
62
 
63
+ /**
64
+ * Selects network to use.
65
+ *
66
+ * @param name network name as it is exposed in the configuration.
67
+ * @return this object for chaining purposes.
68
+ *
69
+ * @see https://docs.couchbase.com/server/current/learn/clusters-and-availability/connectivity.html#alternate-addresses
70
+ * @see https://docs.couchbase.com/server/current/rest-api/rest-set-up-alternate-address.html
71
+ */
72
+ auto network(std::string name) -> behavior_options&
73
+ {
74
+ network_ = std::move(name);
75
+ return *this;
76
+ }
77
+
63
78
  struct built {
64
79
  std::string user_agent_extra;
65
80
  bool show_queries;
@@ -67,13 +82,14 @@ class behavior_options
67
82
  bool enable_mutation_tokens;
68
83
  bool enable_unordered_execution;
69
84
  bool dump_configuration;
85
+ std::string network;
70
86
  };
71
87
 
72
88
  [[nodiscard]] auto build() const -> built
73
89
  {
74
90
  return {
75
- user_agent_extra_, show_queries_, enable_clustermap_notification_, enable_mutation_tokens_,
76
- enable_unordered_execution_, dump_configuration_,
91
+ user_agent_extra_, show_queries_, enable_clustermap_notification_, enable_mutation_tokens_, enable_unordered_execution_,
92
+ dump_configuration_, network_,
77
93
  };
78
94
  }
79
95
 
@@ -84,5 +100,6 @@ class behavior_options
84
100
  bool enable_mutation_tokens_{ true };
85
101
  bool enable_unordered_execution_{ true };
86
102
  bool dump_configuration_{ false };
103
+ std::string network_{ "auto" };
87
104
  };
88
105
  } // namespace couchbase
@@ -18,6 +18,7 @@
18
18
  #pragma once
19
19
 
20
20
  #include <couchbase/collection.hxx>
21
+ #include <couchbase/collection_manager.hxx>
21
22
  #include <couchbase/scope.hxx>
22
23
 
23
24
  #include <memory>
@@ -82,6 +83,19 @@ class bucket
82
83
  return { core_, name_, scope_name };
83
84
  }
84
85
 
86
+ /**
87
+ * Provides access to the collection management services.
88
+ *
89
+ * @return a manager instance
90
+ *
91
+ * @since 1.0.0
92
+ * @committed
93
+ */
94
+ [[nodiscard]] auto collections() const -> collection_manager
95
+ {
96
+ return collection_manager{ core_, name_ };
97
+ }
98
+
85
99
  private:
86
100
  friend class cluster;
87
101
 
@@ -0,0 +1,135 @@
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/create_bucket_options.hxx>
21
+ #include <couchbase/drop_bucket_options.hxx>
22
+ #include <couchbase/flush_bucket_options.hxx>
23
+ #include <couchbase/get_all_buckets_options.hxx>
24
+ #include <couchbase/get_bucket_options.hxx>
25
+ #include <couchbase/update_bucket_options.hxx>
26
+
27
+ #include <future>
28
+ #include <memory>
29
+
30
+ #ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
31
+ namespace couchbase::core
32
+ {
33
+ class cluster;
34
+ } // namespace couchbase::core
35
+ #endif
36
+
37
+ namespace couchbase
38
+ {
39
+ class cluster;
40
+
41
+ class bucket_manager
42
+ {
43
+ public:
44
+ /**
45
+ * Get specific bucket within the cluster
46
+ *
47
+ * @param bucket_name the name of the bucket to get
48
+ * @param options optional parameters
49
+ * @param handler handler that implements @ref get_bucket_handler
50
+ *
51
+ * @since 1.0.0
52
+ * @committed
53
+ */
54
+ void get_bucket(std::string bucket_name, const get_bucket_options& options, get_bucket_handler&& handler) const;
55
+
56
+ [[nodiscard]] auto get_bucket(std::string bucket_name, const get_bucket_options& options = {}) const
57
+ -> std::future<std::pair<manager_error_context, management::cluster::bucket_settings>>;
58
+
59
+ /**
60
+ * Get all buckets on the cluster
61
+ *
62
+ * @param options optional parameters
63
+ * @param handler handler that implements @ref get_all_buckets_handler
64
+ *
65
+ * @since 1.0.0
66
+ * @committed
67
+ */
68
+ void get_all_buckets(const get_all_buckets_options& options, get_all_buckets_handler&& handler) const;
69
+
70
+ [[nodiscard]] auto get_all_buckets(const get_all_buckets_options& options = {}) const
71
+ -> std::future<std::pair<manager_error_context, std::vector<management::cluster::bucket_settings>>>;
72
+
73
+ /**
74
+ * Create a bucket on the cluster
75
+ *
76
+ * @param bucket_settings the settings for the bucket
77
+ * @param options optional parameters
78
+ * @param handler handler that implements @ref create_bucket_handler
79
+ */
80
+ void create_bucket(const management::cluster::bucket_settings& bucket_settings,
81
+ const create_bucket_options& options,
82
+ create_bucket_handler&& handler) const;
83
+
84
+ [[nodiscard]] auto create_bucket(const management::cluster::bucket_settings& bucket_settings,
85
+ const create_bucket_options& options = {}) const -> std::future<manager_error_context>;
86
+
87
+ /**
88
+ * Update an existing bucket
89
+ *
90
+ * @param bucket_settings the settings for the bucket
91
+ * @param options optional parameters
92
+ * @param handler handler that implements @ref update_bucket_handler
93
+ */
94
+ void update_bucket(const management::cluster::bucket_settings& bucket_settings,
95
+ const update_bucket_options& options,
96
+ update_bucket_handler&& handler) const;
97
+
98
+ [[nodiscard]] auto update_bucket(const management::cluster::bucket_settings& bucket_settings,
99
+ const update_bucket_options& options = {}) const -> std::future<manager_error_context>;
100
+
101
+ /**
102
+ * Drop an existing bucket
103
+ *
104
+ * @param bucket_name the name of the bucket to drop
105
+ * @param options optional parameters
106
+ * @param handler handler that implements @ref drop_bucket_handler
107
+ */
108
+ void drop_bucket(std::string bucket_name, const drop_bucket_options& options, drop_bucket_handler&& handler) const;
109
+
110
+ [[nodiscard]] auto drop_bucket(std::string bucket_name, const drop_bucket_options& options = {}) const
111
+ -> std::future<manager_error_context>;
112
+
113
+ /**
114
+ * Flush an existing bucket
115
+ *
116
+ * @param bucket_name the name of the bucket to flush
117
+ * @param options optional parameters
118
+ * @param handler handler that implements @ref flush_bucket_handler
119
+ */
120
+ void flush_bucket(std::string bucket_name, const flush_bucket_options& options, flush_bucket_handler&& handler) const;
121
+
122
+ [[nodiscard]] auto flush_bucket(std::string bucket_name, const flush_bucket_options& options = {}) const
123
+ -> std::future<manager_error_context>;
124
+
125
+ private:
126
+ friend class cluster;
127
+
128
+ explicit bucket_manager(std::shared_ptr<couchbase::core::cluster> core)
129
+ : core_(std::move(core))
130
+ {
131
+ }
132
+
133
+ std::shared_ptr<couchbase::core::cluster> core_;
134
+ };
135
+ } // namespace couchbase
@@ -66,34 +66,4 @@ class build_query_index_options : public common_options<build_query_index_option
66
66
  * @uncommitted
67
67
  */
68
68
  using build_deferred_query_indexes_handler = std::function<void(couchbase::manager_error_context)>;
69
-
70
- #ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
71
- namespace core
72
- {
73
- class cluster;
74
- class query_context;
75
- namespace impl
76
- {
77
-
78
- /**
79
- * @since 1.0.0
80
- * @internal
81
- */
82
- void
83
- initiate_build_deferred_indexes(std::shared_ptr<couchbase::core::cluster> resp1,
84
- std::string bucket_name,
85
- build_query_index_options::built options,
86
- query_context query_ctx,
87
- std::string collection_name,
88
- build_deferred_query_indexes_handler&& handler);
89
-
90
- void
91
- initiate_build_deferred_indexes(std::shared_ptr<couchbase::core::cluster> resp1,
92
- std::string bucket_name,
93
- build_query_index_options::built options,
94
- build_deferred_query_indexes_handler&& handler);
95
-
96
- #endif
97
- } // namespace impl
98
- } // namespace core
99
69
  } // namespace couchbase
@@ -19,6 +19,7 @@
19
19
 
20
20
  #include <couchbase/analytics_options.hxx>
21
21
  #include <couchbase/bucket.hxx>
22
+ #include <couchbase/bucket_manager.hxx>
22
23
  #include <couchbase/cluster_options.hxx>
23
24
  #include <couchbase/query_index_manager.hxx>
24
25
  #include <couchbase/query_options.hxx>
@@ -250,6 +251,19 @@ class cluster
250
251
  return query_index_manager{ core_ };
251
252
  }
252
253
 
254
+ /**
255
+ * Provides access to the bucket management services.
256
+ *
257
+ * @return a manager instance
258
+ *
259
+ * @since 1.0.0
260
+ * @committed
261
+ */
262
+ [[nodiscard]] auto buckets() const -> bucket_manager
263
+ {
264
+ return bucket_manager{ core_ };
265
+ }
266
+
253
267
  /**
254
268
  * Provides access to transaction services.
255
269
  *
@@ -28,6 +28,8 @@
28
28
  #include <couchbase/get_any_replica_options.hxx>
29
29
  #include <couchbase/get_options.hxx>
30
30
  #include <couchbase/insert_options.hxx>
31
+ #include <couchbase/lookup_in_all_replicas_options.hxx>
32
+ #include <couchbase/lookup_in_any_replica_options.hxx>
31
33
  #include <couchbase/lookup_in_options.hxx>
32
34
  #include <couchbase/lookup_in_specs.hxx>
33
35
  #include <couchbase/mutate_in_options.hxx>
@@ -856,6 +858,115 @@ class collection
856
858
  return future;
857
859
  }
858
860
 
861
+ /**
862
+ * Performs lookups to document fragments with default options from all replicas and the active node and returns the result as a vector.
863
+ *
864
+ * @tparam Handler type of the handler that implements @ref lookup_in_all_replicas_handler
865
+ *
866
+ * @param document_id the outer document ID
867
+ * @param specs an object that specifies the types of lookups to perform
868
+ * @param options custom options to modify the lookup options
869
+ * @param handler callable that implements @ref lookup_in_all_replicas_handler
870
+ *
871
+ * @exception errc::key_value::document_not_found the given document id is not found in the collection.
872
+ * @exception errc::common::ambiguous_timeout
873
+ * @exception errc::common::unambiguous_timeout
874
+ *
875
+ * @since 1.0.0
876
+ * @committed
877
+ */
878
+ template<typename Handler>
879
+ void lookup_in_all_replicas(std::string document_id,
880
+ lookup_in_specs specs,
881
+ const lookup_in_all_replicas_options& options,
882
+ Handler&& handler) const
883
+ {
884
+ return core::impl::initiate_lookup_in_all_replicas_operation(
885
+ core_, bucket_name_, scope_name_, name_, std::move(document_id), specs.specs(), options.build(), std::forward<Handler>(handler));
886
+ }
887
+
888
+ /**
889
+ * Performs lookups to document fragments with default options from all replicas and the active node and returns the result as a vector.
890
+ *
891
+ * @param document_id the outer document ID
892
+ * @param specs an object that specifies the types of lookups to perform
893
+ * @param options custom options to modify the lookup options
894
+ * @return future object that carries result of the operation
895
+ *
896
+ * @exception errc::key_value::document_not_found the given document id is not found in the collection.
897
+ * @exception errc::common::ambiguous_timeout
898
+ * @exception errc::common::unambiguous_timeout
899
+ *
900
+ * @since 1.0.0
901
+ * @committed
902
+ */
903
+ [[nodiscard]] auto lookup_in_all_replicas(std::string document_id,
904
+ lookup_in_specs specs,
905
+ const lookup_in_all_replicas_options& options = {}) const
906
+ -> std::future<std::pair<subdocument_error_context, lookup_in_all_replicas_result>>
907
+ {
908
+ auto barrier = std::make_shared<std::promise<std::pair<subdocument_error_context, lookup_in_all_replicas_result>>>();
909
+ auto future = barrier->get_future();
910
+ lookup_in_all_replicas(std::move(document_id), std::move(specs), options, [barrier](auto ctx, auto result) {
911
+ barrier->set_value({ std::move(ctx), std::move(result) });
912
+ });
913
+ return future;
914
+ }
915
+
916
+ /**
917
+ * Performs lookups to document fragments with default options from all replicas and returns the first found.
918
+ *
919
+ * @tparam Handler type of the handler that implements @ref lookup_in_any_replica_handler
920
+ *
921
+ * @param document_id the outer document ID
922
+ * @param specs an object that specifies the types of lookups to perform
923
+ * @param options custom options to modify the lookup options
924
+ *
925
+ * @exception errc::key_value::document_not_found the given document id is not found in the collection.
926
+ * @exception errc::common::ambiguous_timeout
927
+ * @exception errc::common::unambiguous_timeout
928
+ *
929
+ * @since 1.0.0
930
+ * @committed
931
+ */
932
+ template<typename Handler>
933
+ void lookup_in_any_replica(std::string document_id,
934
+ lookup_in_specs specs,
935
+ const lookup_in_any_replica_options& options,
936
+ Handler&& handler) const
937
+ {
938
+ return core::impl::initiate_lookup_in_any_replica_operation(
939
+ core_, bucket_name_, scope_name_, name_, std::move(document_id), specs.specs(), options.build(), std::forward<Handler>(handler));
940
+ }
941
+
942
+ /**
943
+ * Performs lookups to document fragments with default options from all replicas and returns the first found.
944
+ *
945
+ * @param document_id the outer document ID
946
+ * @param specs an object that specifies the types of lookups to perform
947
+ * @param options custom options to modify the lookup options
948
+ * @return future object that carries result of the operation
949
+ *
950
+ * @exception errc::key_value::document_not_found the given document id is not found in the collection.
951
+ * @exception errc::common::ambiguous_timeout
952
+ * @exception errc::common::unambiguous_timeout
953
+ *
954
+ * @since 1.0.0
955
+ * @committed
956
+ */
957
+ [[nodiscard]] auto lookup_in_any_replica(std::string document_id,
958
+ lookup_in_specs specs,
959
+ const lookup_in_any_replica_options& options = {}) const
960
+ -> std::future<std::pair<subdocument_error_context, lookup_in_replica_result>>
961
+ {
962
+ auto barrier = std::make_shared<std::promise<std::pair<subdocument_error_context, lookup_in_replica_result>>>();
963
+ auto future = barrier->get_future();
964
+ lookup_in_any_replica(std::move(document_id), std::move(specs), options, [barrier](auto ctx, auto result) {
965
+ barrier->set_value({ std::move(ctx), std::move(result) });
966
+ });
967
+ return future;
968
+ }
969
+
859
970
  /**
860
971
  * Gets a document for a given id and places a pessimistic lock on it for mutations
861
972
  *
@@ -0,0 +1,160 @@
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/create_collection_options.hxx>
21
+ #include <couchbase/create_scope_options.hxx>
22
+ #include <couchbase/drop_collection_options.hxx>
23
+ #include <couchbase/drop_scope_options.hxx>
24
+ #include <couchbase/get_all_scopes_options.hxx>
25
+ #include <couchbase/management/collection_spec.hxx>
26
+ #include <couchbase/update_collection_options.hxx>
27
+
28
+ #include <future>
29
+ #include <memory>
30
+
31
+ #ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
32
+ namespace couchbase::core
33
+ {
34
+ class cluster;
35
+ } // namespace couchbase::core
36
+ #endif
37
+
38
+ namespace couchbase
39
+ {
40
+ class bucket;
41
+
42
+ class collection_manager
43
+ {
44
+ public:
45
+ /**
46
+ * Get all scopes on the bucket
47
+ *
48
+ * @param options optional parameters
49
+ * @param handler handler that implements @ref get_all_scopes_handler
50
+ *
51
+ * @since 1.0.0
52
+ */
53
+ void get_all_scopes(const get_all_scopes_options& options, get_all_scopes_handler&& handler) const;
54
+
55
+ [[nodiscard]] auto get_all_scopes(const get_all_scopes_options& options = {}) const
56
+ -> std::future<std::pair<manager_error_context, std::vector<management::bucket::scope_spec>>>;
57
+
58
+ /**
59
+ * Creates a new collection
60
+ *
61
+ * @param scope_name the name of the scope to create the collection on
62
+ * @param collection_name the collection name
63
+ * @param settings create collection settings
64
+ * @param options optional parameters
65
+ * @param handler handler that implements @ref create_collection_handler
66
+ *
67
+ * @since 1.0.0
68
+ */
69
+ void create_collection(std::string scope_name,
70
+ std::string collection_name,
71
+ const create_collection_settings& settings,
72
+ const create_collection_options& options,
73
+ create_collection_handler&& handler) const;
74
+
75
+ [[nodiscard]] auto create_collection(std::string scope_name,
76
+ std::string collection_name,
77
+ const create_collection_settings& settings = {},
78
+ const create_collection_options& options = {}) const -> std::future<manager_error_context>;
79
+ /**
80
+ * Updates an existing collection
81
+ *
82
+ * @param scope_name the name of the scope on which the collection exists
83
+ * @param collection_name the collection name
84
+ * @param settings update collection settings
85
+ * @param options optional parameters
86
+ * @param handler handler that implements @ref update_collection_handler
87
+ *
88
+ * @since 1.0.0
89
+ */
90
+ void update_collection(std::string scope_name,
91
+ std::string collection_name,
92
+ const update_collection_settings& settings,
93
+ const update_collection_options& options,
94
+ update_collection_handler&& handler) const;
95
+
96
+ [[nodiscard]] auto update_collection(std::string scope_name,
97
+ std::string collection_name,
98
+ const update_collection_settings& settings,
99
+ const update_collection_options& options = {}) const -> std::future<manager_error_context>;
100
+
101
+ /**
102
+ * Drops a collection
103
+ *
104
+ * @param scope_name the name of the scope on which the collection exists
105
+ * @param collection_name the collection name
106
+ * @param options optional parameters
107
+ * @param handler handler that implements @ref drop_collection_handler
108
+ *
109
+ * @since 1.0.0
110
+ */
111
+ void drop_collection(std::string scope_name,
112
+ std::string collection_name,
113
+ const drop_collection_options& options,
114
+ drop_collection_handler&& handler) const;
115
+
116
+ [[nodiscard]] auto drop_collection(std::string scope_name,
117
+ std::string collection_name,
118
+ const drop_collection_options& options = {}) const -> std::future<manager_error_context>;
119
+
120
+ /**
121
+ * Creates a scope on the bucket
122
+ *
123
+ * @param scope_name the scope name
124
+ * @param options optional parameters
125
+ * @param handler handler that implements @ref create_scope_handler
126
+ *
127
+ * @since 1.0.0
128
+ */
129
+ void create_scope(std::string scope_name, const create_scope_options& options, create_scope_handler&& handler) const;
130
+
131
+ [[nodiscard]] auto create_scope(std::string scope_name, const create_scope_options& options = {}) const
132
+ -> std::future<manager_error_context>;
133
+
134
+ /**
135
+ * Drops a scope on the bucket
136
+ *
137
+ * @param scope_name the scope name
138
+ * @param options optional parameters
139
+ * @param handler handler that implements @ref drop_scope_handler
140
+ *
141
+ * @since 1.0.0
142
+ */
143
+ void drop_scope(std::string scope_name, const drop_scope_options& options, drop_scope_handler&& handler) const;
144
+
145
+ [[nodiscard]] auto drop_scope(std::string scope_name, const drop_scope_options& options = {}) const
146
+ -> std::future<manager_error_context>;
147
+
148
+ private:
149
+ friend class bucket;
150
+
151
+ explicit collection_manager(std::shared_ptr<couchbase::core::cluster> core, std::string bucket_name)
152
+ : core_(std::move(core))
153
+ , bucket_name_(std::move(bucket_name))
154
+ {
155
+ }
156
+
157
+ std::shared_ptr<couchbase::core::cluster> core_;
158
+ std::string bucket_name_;
159
+ };
160
+ } // namespace couchbase
@@ -64,13 +64,7 @@ class collection_query_index_manager
64
64
  void get_all_indexes(const get_all_query_indexes_options& options, get_all_query_indexes_handler&& handler) const;
65
65
 
66
66
  [[nodiscard]] auto get_all_indexes(const get_all_query_indexes_options& options) const
67
- -> std::future<std::pair<manager_error_context, std::vector<couchbase::management::query::index>>>
68
- {
69
- auto barrier = std::make_shared<std::promise<std::pair<manager_error_context, std::vector<couchbase::management::query::index>>>>();
70
- auto future = barrier->get_future();
71
- get_all_indexes(options, [barrier](auto ctx, auto resp) { barrier->set_value({ ctx, resp }); });
72
- return future;
73
- }
67
+ -> std::future<std::pair<manager_error_context, std::vector<couchbase::management::query::index>>>;
74
68
  /**
75
69
  * Create an index on the collection.
76
70
  *
@@ -89,13 +83,7 @@ class collection_query_index_manager
89
83
 
90
84
  [[nodiscard]] auto create_index(std::string index_name,
91
85
  std::vector<std::string> fields,
92
- const create_query_index_options& options) const -> std::future<manager_error_context>
93
- {
94
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
95
- auto future = barrier->get_future();
96
- create_index(std::move(index_name), std::move(fields), options, [barrier](auto ctx) { barrier->set_value(ctx); });
97
- return future;
98
- }
86
+ const create_query_index_options& options) const -> std::future<manager_error_context>;
99
87
 
100
88
  /**
101
89
  * Create a primary index on a collection.
@@ -108,13 +96,7 @@ class collection_query_index_manager
108
96
  */
109
97
  void create_primary_index(const create_primary_query_index_options& options, create_query_index_handler&& handler) const;
110
98
 
111
- [[nodiscard]] auto create_primary_index(const create_primary_query_index_options& options) -> std::future<manager_error_context>
112
- {
113
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
114
- auto future = barrier->get_future();
115
- create_primary_index(options, [barrier](auto ctx) { barrier->set_value(ctx); });
116
- return future;
117
- }
99
+ [[nodiscard]] auto create_primary_index(const create_primary_query_index_options& options) -> std::future<manager_error_context>;
118
100
  /**
119
101
  * Drop primary index on a collection.
120
102
  *
@@ -126,13 +108,7 @@ class collection_query_index_manager
126
108
  */
127
109
  void drop_primary_index(const drop_primary_query_index_options& options, drop_query_index_handler&& handler) const;
128
110
 
129
- [[nodiscard]] auto drop_primary_index(const drop_primary_query_index_options& options) const -> std::future<manager_error_context>
130
- {
131
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
132
- auto future = barrier->get_future();
133
- drop_primary_index(options, [barrier](auto ctx) { barrier->set_value(ctx); });
134
- return future;
135
- }
111
+ [[nodiscard]] auto drop_primary_index(const drop_primary_query_index_options& options) const -> std::future<manager_error_context>;
136
112
 
137
113
  /**
138
114
  * Drop index in collection.
@@ -146,13 +122,7 @@ class collection_query_index_manager
146
122
  */
147
123
  void drop_index(std::string index_name, const drop_query_index_options& options, drop_query_index_handler&& handler) const;
148
124
 
149
- [[nodiscard]] auto drop_index(std::string index_name, const drop_query_index_options& options) -> std::future<manager_error_context>
150
- {
151
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
152
- auto future = barrier->get_future();
153
- drop_index(std::move(index_name), options, [barrier](auto ctx) { barrier->set_value(ctx); });
154
- return future;
155
- }
125
+ [[nodiscard]] auto drop_index(std::string index_name, const drop_query_index_options& options) -> std::future<manager_error_context>;
156
126
  /**
157
127
  * Builds all currently deferred indexes in this collection.
158
128
  *
@@ -166,13 +136,7 @@ class collection_query_index_manager
166
136
  */
167
137
  void build_deferred_indexes(const build_query_index_options& options, build_deferred_query_indexes_handler&& handler) const;
168
138
 
169
- [[nodiscard]] auto build_deferred_indexes(const build_query_index_options& options) const -> std::future<manager_error_context>
170
- {
171
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
172
- auto future = barrier->get_future();
173
- build_deferred_indexes(options, [barrier](auto ctx) { barrier->set_value(std::move(ctx)); });
174
- return future;
175
- }
139
+ [[nodiscard]] auto build_deferred_indexes(const build_query_index_options& options) const -> std::future<manager_error_context>;
176
140
 
177
141
  /**
178
142
  * Polls the state of a set of indexes, until they all are online.
@@ -189,12 +153,7 @@ class collection_query_index_manager
189
153
  watch_query_indexes_handler&& handler) const;
190
154
 
191
155
  [[nodiscard]] auto watch_indexes(std::vector<std::string> index_names, const watch_query_indexes_options& options)
192
- {
193
- auto barrier = std::make_shared<std::promise<manager_error_context>>();
194
- auto future = barrier->get_future();
195
- watch_indexes(std::move(index_names), options, [barrier](auto ctx) { barrier->set_value(ctx); });
196
- return future;
197
- }
156
+ -> std::future<manager_error_context>;
198
157
 
199
158
  private:
200
159
  friend class collection;