Couchbase C++ SDK 1.0.1 (rev. 58d46d7)
Loading...
Searching...
No Matches
collection.hxx
Go to the documentation of this file.
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
23#include <couchbase/error.hxx>
25#include <couchbase/expiry.hxx>
47
48#include <future>
49#include <memory>
50
51namespace couchbase
52{
53#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
54namespace core
55{
56class cluster;
57} // namespace core
58class bucket;
59class scope;
60class collection_impl;
61#endif
62
70{
71public:
78 static constexpr auto default_name{ "_default" };
79
88 [[nodiscard]] auto bucket_name() const -> const std::string&;
89
98 [[nodiscard]] auto scope_name() const -> const std::string&;
99
108 [[nodiscard]] auto name() const -> const std::string&;
109
118 [[nodiscard]] auto binary() const -> binary_collection;
119
135 void get(std::string document_id, const get_options& options, get_handler&& handler) const;
136
152 [[nodiscard]] auto get(std::string document_id, const get_options& options = {}) const
153 -> std::future<std::pair<error, get_result>>;
154
171 void get_and_touch(std::string document_id,
172 std::chrono::seconds duration,
173 const get_and_touch_options& options,
174 get_and_touch_handler&& handler) const;
175
192 [[nodiscard]] auto get_and_touch(std::string document_id,
193 std::chrono::seconds duration,
194 const get_and_touch_options& options = {}) const
195 -> std::future<std::pair<error, get_result>>;
196
213 void get_and_touch(std::string document_id,
214 std::chrono::system_clock::time_point time_point,
215 const get_and_touch_options& options,
216 get_and_touch_handler&& handler) const;
217
234 [[nodiscard]] auto get_and_touch(std::string document_id,
235 std::chrono::system_clock::time_point time_point,
236 const get_and_touch_options& options = {}) const
237 -> std::future<std::pair<error, get_result>>;
238
255 void touch(std::string document_id,
256 std::chrono::seconds duration,
257 const touch_options& options,
258 touch_handler&& handler) const;
259
276 [[nodiscard]] auto touch(std::string document_id,
277 std::chrono::seconds duration,
278 const touch_options& options = {}) const
279 -> std::future<std::pair<error, result>>;
280
297 void touch(std::string document_id,
298 std::chrono::system_clock::time_point time_point,
299 const touch_options& options,
300 touch_handler&& handler) const;
301
318 [[nodiscard]] auto touch(std::string document_id,
319 std::chrono::system_clock::time_point time_point,
320 const touch_options& options = {}) const
321 -> std::future<std::pair<error, result>>;
322
340 void get_any_replica(std::string document_id,
341 const get_any_replica_options& options,
342 get_any_replica_handler&& handler) const;
343
361 [[nodiscard]] auto get_any_replica(std::string document_id,
362 const get_any_replica_options& options = {}) const
363 -> std::future<std::pair<error, get_replica_result>>;
364
381 void get_all_replicas(std::string document_id,
382 const get_all_replicas_options& options,
383 get_all_replicas_handler&& handler) const;
384
401 [[nodiscard]] auto get_all_replicas(std::string document_id,
402 const get_all_replicas_options& options = {}) const
403 -> std::future<std::pair<error, get_all_replicas_result>>;
404
420 void upsert(std::string document_id,
421 codec::encoded_value document,
422 const upsert_options& options,
423 upsert_handler&& handler) const;
424
442 template<typename Transcoder = codec::default_json_transcoder, typename Document>
443 void upsert(std::string document_id,
444 Document document,
445 const upsert_options& options,
446 upsert_handler&& handler) const
447 {
448 return upsert(
449 std::move(document_id), Transcoder::encode(document), options, std::move(handler));
450 }
451
467 [[nodiscard]] auto upsert(std::string document_id,
468 codec::encoded_value document,
469 const upsert_options& options) const
470 -> std::future<std::pair<error, mutation_result>>;
471
489 template<typename Transcoder = codec::default_json_transcoder, typename Document>
490 [[nodiscard]] auto upsert(std::string document_id,
491 const Document& document,
492 const upsert_options& options = {}) const
493 -> std::future<std::pair<error, mutation_result>>
494 {
495 return upsert(std::move(document_id), Transcoder::encode(document), options);
496 }
497
512 void insert(std::string document_id,
513 codec::encoded_value document,
514 const insert_options& options,
515 insert_handler&& handler) const;
516
536 template<typename Transcoder = codec::default_json_transcoder,
537 typename Document,
538 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
539 void insert(std::string document_id,
540 Document document,
541 const insert_options& options,
542 insert_handler&& handler) const
543 {
544 return insert(
545 std::move(document_id), Transcoder::encode(document), options, std::move(handler));
546 }
547
562 [[nodiscard]] auto insert(std::string document_id,
563 codec::encoded_value document,
564 const insert_options& options) const
565 -> std::future<std::pair<error, mutation_result>>;
566
586 template<typename Transcoder = codec::default_json_transcoder,
587 typename Document,
588 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
589 [[nodiscard]] auto insert(std::string document_id,
590 const Document& document,
591 const insert_options& options = {}) const
592 -> std::future<std::pair<error, mutation_result>>
593 {
594 return insert(std::move(document_id), Transcoder::encode(document), options);
595 }
596
611 void replace(std::string document_id,
612 codec::encoded_value document,
613 const replace_options& options,
614 replace_handler&& handler) const;
615
637 template<typename Transcoder = codec::default_json_transcoder,
638 typename Document,
639 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
640 void replace(std::string document_id,
641 Document document,
642 const replace_options& options,
643 replace_handler&& handler) const
644 {
645 return replace(
646 std::move(document_id), Transcoder::encode(document), options, std::move(handler));
647 }
648
663 [[nodiscard]] auto replace(std::string document_id,
664 codec::encoded_value document,
665 const replace_options& options) const
666 -> std::future<std::pair<error, mutation_result>>;
667
689 template<typename Transcoder = codec::default_json_transcoder,
690 typename Document,
691 std::enable_if_t<!std::is_same_v<codec::encoded_value, Document>, bool> = true>
692 [[nodiscard]] auto replace(std::string document_id,
693 const Document& document,
694 const replace_options& options = {}) const
695 -> std::future<std::pair<error, mutation_result>>
696 {
697 return replace(std::move(document_id), Transcoder::encode(document), options);
698 }
699
717 void remove(std::string document_id,
718 const remove_options& options,
719 remove_handler&& handler) const;
720
738 [[nodiscard]] auto remove(std::string document_id, const remove_options& options = {}) const
739 -> std::future<std::pair<error, mutation_result>>;
740
761 void mutate_in(std::string document_id,
762 const mutate_in_specs& specs,
763 const mutate_in_options& options,
764 mutate_in_handler&& handler) const;
765
786 [[nodiscard]] auto mutate_in(std::string document_id,
787 const mutate_in_specs& specs,
788 const mutate_in_options& options = {}) const
789 -> std::future<std::pair<error, mutate_in_result>>;
790
807 void lookup_in(std::string document_id,
808 const lookup_in_specs& specs,
809 const lookup_in_options& options,
810 lookup_in_handler&& handler) const;
811
828 [[nodiscard]] auto lookup_in(std::string document_id,
829 const lookup_in_specs& specs,
830 const lookup_in_options& options = {}) const
831 -> std::future<std::pair<error, lookup_in_result>>;
832
850 void lookup_in_all_replicas(std::string document_id,
851 const lookup_in_specs& specs,
852 const lookup_in_all_replicas_options& options,
853 lookup_in_all_replicas_handler&& handler) const;
854
872 [[nodiscard]] auto lookup_in_all_replicas(std::string document_id,
873 const lookup_in_specs& specs,
874 const lookup_in_all_replicas_options& options = {})
875 const -> std::future<std::pair<error, lookup_in_all_replicas_result>>;
876
894 void lookup_in_any_replica(std::string document_id,
895 const lookup_in_specs& specs,
896 const lookup_in_any_replica_options& options,
897 lookup_in_any_replica_handler&& handler) const;
898
916 [[nodiscard]] auto lookup_in_any_replica(std::string document_id,
917 const lookup_in_specs& specs,
918 const lookup_in_any_replica_options& options = {}) const
919 -> std::future<std::pair<error, lookup_in_replica_result>>;
920
932 void get_and_lock(std::string document_id,
933 std::chrono::seconds lock_duration,
934 const get_and_lock_options& options,
935 get_and_lock_handler&& handler) const;
936
948 [[nodiscard]] auto get_and_lock(std::string document_id,
949 std::chrono::seconds lock_duration,
950 const get_and_lock_options& options = {}) const
951 -> std::future<std::pair<error, get_result>>;
952
971 void unlock(std::string document_id,
973 const unlock_options& options,
974 unlock_handler&& handler) const;
975
994 [[nodiscard]] auto unlock(std::string document_id,
996 const unlock_options& options = {}) const -> std::future<error>;
997
1011 void exists(std::string document_id,
1012 const exists_options& options,
1013 exists_handler&& handler) const;
1014
1028 [[nodiscard]] auto exists(std::string document_id, const exists_options& options = {}) const
1029 -> std::future<std::pair<error, exists_result>>;
1030
1046 void scan(const scan_type& scan_type, const scan_options& options, scan_handler&& handler) const;
1047
1063 [[nodiscard]] auto scan(const scan_type& scan_type, const scan_options& options = {}) const
1064 -> std::future<std::pair<error, scan_result>>;
1065
1066 [[nodiscard]] auto query_indexes() const -> collection_query_index_manager;
1067
1068private:
1069 friend class bucket;
1070 friend class scope;
1071
1072 collection(core::cluster core,
1073 std::string_view bucket_name,
1074 std::string_view scope_name,
1075 std::string_view name);
1076
1077 std::shared_ptr<collection_impl> impl_;
1078};
1079} // namespace couchbase
Allows to perform certain operations on non-JSON documents.
Definition binary_collection.hxx:47
Provides access to Couchbase bucket.
Definition bucket.hxx:45
CAS is a special type that represented in protocol using unsigned 64-bit integer, but only equality c...
Definition cas.hxx:34
The cluster is the main entry point when connecting to a Couchbase cluster.
Definition cluster.hxx:60
The Query Index Manager interface contains the means for managing indexes used for queries.
Definition collection_query_index_manager.hxx:53
The collection provides access to all collection APIs.
Definition collection.hxx:70
auto touch(std::string document_id, std::chrono::system_clock::time_point time_point, const touch_options &options={}) const -> std::future< std::pair< error, result > >
Updates the expiration a document given an id, without modifying or returning its value.
auto replace(std::string document_id, codec::encoded_value document, const replace_options &options) const -> std::future< std::pair< error, mutation_result > >
Replaces a body of the document which already exists with specified encoded body.
void replace(std::string document_id, Document document, const replace_options &options, replace_handler &&handler) const
Replaces a full document which already exists.
Definition collection.hxx:640
auto insert(std::string document_id, const Document &document, const insert_options &options={}) const -> std::future< std::pair< error, mutation_result > >
Inserts a full document which does not exist yet with custom options.
Definition collection.hxx:589
auto scan(const scan_type &scan_type, const scan_options &options={}) const -> std::future< std::pair< error, scan_result > >
Performs a key-value scan operation on the collection.
auto mutate_in(std::string document_id, const mutate_in_specs &specs, const mutate_in_options &options={}) const -> std::future< std::pair< error, mutate_in_result > >
Performs mutations to document fragments.
void remove(std::string document_id, const remove_options &options, remove_handler &&handler) const
Removes a Document from a collection.
auto bucket_name() const -> const std::string &
Returns name of the bucket where the collection is defined.
auto unlock(std::string document_id, couchbase::cas cas, const unlock_options &options={}) const -> std::future< error >
Unlocks a document if it has been locked previously, with default options.
void lookup_in_all_replicas(std::string document_id, const lookup_in_specs &specs, const lookup_in_all_replicas_options &options, lookup_in_all_replicas_handler &&handler) const
Performs lookups to document fragments with default options from all replicas and the active node and...
void get_and_lock(std::string document_id, std::chrono::seconds lock_duration, const get_and_lock_options &options, get_and_lock_handler &&handler) const
Gets a document for a given id and places a pessimistic lock on it for mutations.
static constexpr auto default_name
Constant for the name of the default collection in the bucket.
Definition collection.hxx:78
auto binary() const -> binary_collection
Provides access to the binary APIs, not used for JSON documents.
void scan(const scan_type &scan_type, const scan_options &options, scan_handler &&handler) const
Performs a key-value scan operation on the collection.
void lookup_in_any_replica(std::string document_id, const lookup_in_specs &specs, const lookup_in_any_replica_options &options, lookup_in_any_replica_handler &&handler) const
Performs lookups to document fragments with default options from all replicas and returns the first f...
void touch(std::string document_id, std::chrono::system_clock::time_point time_point, const touch_options &options, touch_handler &&handler) const
Updates the expiration a document given an id, without modifying or returning its value.
void exists(std::string document_id, const exists_options &options, exists_handler &&handler) const
Checks if the document exists on the server.
void get_and_touch(std::string document_id, std::chrono::seconds duration, const get_and_touch_options &options, get_and_touch_handler &&handler) const
Fetches a full document and resets its expiration time to the value provided.
auto lookup_in_all_replicas(std::string document_id, const lookup_in_specs &specs, const lookup_in_all_replicas_options &options={}) const -> std::future< std::pair< error, lookup_in_all_replicas_result > >
Performs lookups to document fragments with default options from all replicas and the active node and...
void get_any_replica(std::string document_id, const get_any_replica_options &options, get_any_replica_handler &&handler) const
Reads all available replicas, and returns the first found.
auto get_and_touch(std::string document_id, std::chrono::seconds duration, const get_and_touch_options &options={}) const -> std::future< std::pair< error, get_result > >
Fetches a full document and resets its expiration time to the value provided.
void lookup_in(std::string document_id, const lookup_in_specs &specs, const lookup_in_options &options, lookup_in_handler &&handler) const
Performs lookups to document fragments with default options.
void replace(std::string document_id, codec::encoded_value document, const replace_options &options, replace_handler &&handler) const
Replaces a body of the document which already exists with specified encoded body.
auto replace(std::string document_id, const Document &document, const replace_options &options={}) const -> std::future< std::pair< error, mutation_result > >
Replaces a full document which already exists.
Definition collection.hxx:692
auto get_and_touch(std::string document_id, std::chrono::system_clock::time_point time_point, const get_and_touch_options &options={}) const -> std::future< std::pair< error, get_result > >
Fetches a full document and resets its expiration time to the absolute value provided.
auto upsert(std::string document_id, const Document &document, const upsert_options &options={}) const -> std::future< std::pair< error, mutation_result > >
Upserts a full document which might or might not exist yet with custom options.
Definition collection.hxx:490
auto touch(std::string document_id, std::chrono::seconds duration, const touch_options &options={}) const -> std::future< std::pair< error, result > >
Updates the expiration a document given an id, without modifying or returning its value.
void upsert(std::string document_id, codec::encoded_value document, const upsert_options &options, upsert_handler &&handler) const
Upserts an encoded body of the document which might or might not exist yet, with custom options.
void upsert(std::string document_id, Document document, const upsert_options &options, upsert_handler &&handler) const
Upserts a full document which might or might not exist yet with custom options.
Definition collection.hxx:443
auto remove(std::string document_id, const remove_options &options={}) const -> std::future< std::pair< error, mutation_result > >
Removes a Document from a collection.
auto name() const -> const std::string &
Returns name of the collection.
auto upsert(std::string document_id, codec::encoded_value document, const upsert_options &options) const -> std::future< std::pair< error, mutation_result > >
Upserts an encoded body of the document which might or might not exist yet, with custom options.
auto lookup_in(std::string document_id, const lookup_in_specs &specs, const lookup_in_options &options={}) const -> std::future< std::pair< error, lookup_in_result > >
Performs lookups to document fragments with default options.
auto exists(std::string document_id, const exists_options &options={}) const -> std::future< std::pair< error, exists_result > >
Checks if the document exists on the server.
void insert(std::string document_id, codec::encoded_value document, const insert_options &options, insert_handler &&handler) const
Inserts an encoded body of the document which does not exist yet with custom options.
void get(std::string document_id, const get_options &options, get_handler &&handler) const
Fetches the full document from this collection.
auto get_all_replicas(std::string document_id, const get_all_replicas_options &options={}) const -> std::future< std::pair< error, get_all_replicas_result > >
Reads from all available replicas and the active node and returns the results as a vector.
auto get_and_lock(std::string document_id, std::chrono::seconds lock_duration, const get_and_lock_options &options={}) const -> std::future< std::pair< error, get_result > >
Gets a document for a given id and places a pessimistic lock on it for mutations.
auto get_any_replica(std::string document_id, const get_any_replica_options &options={}) const -> std::future< std::pair< error, get_replica_result > >
Reads all available replicas, and returns the first found.
auto lookup_in_any_replica(std::string document_id, const lookup_in_specs &specs, const lookup_in_any_replica_options &options={}) const -> std::future< std::pair< error, lookup_in_replica_result > >
Performs lookups to document fragments with default options from all replicas and returns the first f...
void get_all_replicas(std::string document_id, const get_all_replicas_options &options, get_all_replicas_handler &&handler) const
Reads from all available replicas and the active node and returns the results as a vector.
auto query_indexes() const -> collection_query_index_manager
void mutate_in(std::string document_id, const mutate_in_specs &specs, const mutate_in_options &options, mutate_in_handler &&handler) const
Performs mutations to document fragments.
void unlock(std::string document_id, couchbase::cas cas, const unlock_options &options, unlock_handler &&handler) const
Unlocks a document if it has been locked previously, with default options.
auto insert(std::string document_id, codec::encoded_value document, const insert_options &options) const -> std::future< std::pair< error, mutation_result > >
Inserts an encoded body of the document which does not exist yet with custom options.
auto scope_name() const -> const std::string &
Returns name of the scope where the collection is defined.
void touch(std::string document_id, std::chrono::seconds duration, const touch_options &options, touch_handler &&handler) const
Updates the expiration a document given an id, without modifying or returning its value.
void get_and_touch(std::string document_id, std::chrono::system_clock::time_point time_point, const get_and_touch_options &options, get_and_touch_handler &&handler) const
Fetches a full document and resets its expiration time to the absolute value provided.
void insert(std::string document_id, Document document, const insert_options &options, insert_handler &&handler) const
Inserts a full document which does not exist yet with custom options.
Definition collection.hxx:539
Definition lookup_in_specs.hxx:34
Definition mutate_in_specs.hxx:76
The scope identifies a group of collections and allows high application density as a result.
Definition scope.hxx:47
json_transcoder< tao_json_serializer > default_json_transcoder
Definition default_json_transcoder.hxx:28
Represents a single item from the result of collection::scan()
Definition allow_querying_search_index_options.hxx:28
std::function< void(error, get_replica_result)> get_any_replica_handler
The signature for the handler of the collection::get_any_replica() operation.
Definition get_any_replica_options.hxx:92
std::function< void(error, mutation_result)> insert_handler
The signature for the handler of the collection::insert() operation.
Definition insert_options.hxx:114
@ replace
Replace the document, fail if it does not exist.
@ upsert
Replace the document or create it if it does not exist.
@ insert
Create the document, fail if it exists.
std::function< void(error, lookup_in_result)> lookup_in_handler
The signature for the handler of the collection::lookup_in() operation.
Definition lookup_in_options.hxx:94
std::function< void(error, get_result)> get_handler
The signature for the handler of the collection::get() operation.
Definition get_options.hxx:111
std::function< void(error, get_all_replicas_result)> get_all_replicas_handler
The signature for the handler of the collection::get_all_replicas() operation.
Definition get_all_replicas_options.hxx:101
std::function< void(error, get_result)> get_and_lock_handler
The signature for the handler of the collection::get_and_lock() operation.
Definition get_and_lock_options.hxx:70
std::function< void(error, mutation_result)> remove_handler
The signature for the handler of the collection::remove() operation.
Definition remove_options.hxx:103
std::function< void(error, mutation_result)> upsert_handler
The signature for the handler of the collection::upsert() operation.
Definition upsert_options.hxx:138
std::function< void(error, mutate_in_result)> mutate_in_handler
The signature for the handler of the collection::mutate_in() operation.
Definition mutate_in_options.hxx:219
std::function< void(error, lookup_in_all_replicas_result)> lookup_in_all_replicas_handler
The signature for the handler of the collection::lookup_in_all_replicas() operation.
Definition lookup_in_all_replicas_options.hxx:106
std::function< void(error, scan_result)> scan_handler
The signature for the handler of the collection::scan() operation.
Definition scan_options.hxx:168
std::function< void(error, result)> touch_handler
The signature for the handler of the collection::touch() operation.
Definition touch_options.hxx:70
std::function< void(error, mutation_result)> replace_handler
The signature for the handler of the collection::replace() operation.
Definition replace_options.hxx:167
std::function< void(error, lookup_in_replica_result)> lookup_in_any_replica_handler
The signature for the handler of the collection::lookup_in_any_replica() operation.
Definition lookup_in_any_replica_options.hxx:97
std::function< void(error)> unlock_handler
The signature for the handler of the collection::unlock() operation.
Definition unlock_options.hxx:73
std::function< void(error, get_result)> get_and_touch_handler
The signature for the handler of the collection::get_and_touch() operation.
Definition get_and_touch_options.hxx:70
std::function< void(error, exists_result)> exists_handler
The signature for the handler of the collection::exists() operation.
Definition exists_options.hxx:74
Definition encoded_value.hxx:27
Options for collection::exists().
Definition exists_options.hxx:41
Options for collection::get_all_replicas().
Definition get_all_replicas_options.hxx:36
Options for collection::get_and_lock().
Definition get_and_lock_options.hxx:37
Options for collection::get_and_touch().
Definition get_and_touch_options.hxx:37
Options for collection::get_any_replica().
Definition get_any_replica_options.hxx:35
Options for collection::get().
Definition get_options.hxx:37
Options for collection::insert().
Definition insert_options.hxx:41
Options for collection::lookup_in_all_replicas().
Definition lookup_in_all_replicas_options.hxx:41
Options for collection::lookup_in_any_replica().
Definition lookup_in_any_replica_options.hxx:40
Options for collection::lookup_in().
Definition lookup_in_options.hxx:44
Options for collection::mutate_in().
Definition mutate_in_options.hxx:44
Options for collection::remove().
Definition remove_options.hxx:41
Options for collection::replace().
Definition replace_options.hxx:41
Options for collection::scan().
Definition scan_options.hxx:40
The base class for the different scan types.
Definition scan_type.hxx:96
Options for collection::touch().
Definition touch_options.hxx:37
Options for collection::unlock().
Definition unlock_options.hxx:40
Options for collection::upsert().
Definition upsert_options.hxx:41