Couchbase C++ SDK 1.4.0 (rev. 59aa900)
Loading...
Searching...
No Matches
scan_result_item.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 2024. 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/cas.hxx>
24#include <couchbase/result.hxx>
25
26#include <chrono>
27#include <optional>
28#include <string>
29#include <type_traits>
30#include <utility>
31
38namespace couchbase
39{
40#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
41namespace crypto
42{
43class manager;
44} // namespace crypto
45#endif
46
48{
49public:
56 scan_result_item() = default;
57
70 scan_result_item(std::string id,
73 std::optional<std::chrono::system_clock::time_point> expiry_time,
74 std::shared_ptr<crypto::manager> crypto_manager = {})
75 : result{ cas }
76 , id_{ std::move(id) }
77 , id_only_{ false }
78 , value_{ std::move(value) }
79 , expiry_time_{ expiry_time }
80 , crypto_manager_{ std::move(crypto_manager) }
81 {
82 }
83
92 explicit scan_result_item(std::string id)
93 : id_{ std::move(id) }
94 , id_only_{ true }
95 {
96 }
97
98 bool operator==(const scan_result_item& other) const
99 {
100 return id_ == other.id_ && cas() == other.cas();
101 }
102
111 [[nodiscard]] auto id() const -> const std::string&
112 {
113 return id_;
114 }
115
125 [[nodiscard]] auto id_only() const -> bool
126 {
127 return id_only_;
128 }
129
145 template<typename Document,
146 typename Transcoder = codec::default_json_transcoder,
147 std::enable_if_t<!codec::is_transcoder_v<Document>, bool> = true,
148 std::enable_if_t<codec::is_transcoder_v<Transcoder>, bool> = true>
149 [[nodiscard]] auto content_as() const -> Document
150 {
151 if (id_only_) {
152 return {};
153 }
155 return Transcoder::template decode<Document>(value_, crypto_manager_);
156 } else {
157 return Transcoder::template decode<Document>(value_);
158 }
159 }
160
174 [[nodiscard]] auto expiry_time() const
175 -> const std::optional<std::chrono::system_clock::time_point>&
176 {
177 return expiry_time_;
178 }
179
180private:
181 std::string id_{};
182 bool id_only_{};
183 codec::encoded_value value_{};
184 std::optional<std::chrono::system_clock::time_point> expiry_time_{};
185 std::shared_ptr<crypto::manager> crypto_manager_{};
186};
187} // namespace couchbase
CAS is a special type that represented in protocol using unsigned 64-bit integer, but only equality c...
Definition cas.hxx:34
Base class for operations of data service.
Definition result.hxx:35
auto cas() const -> couchbase::cas
Definition result.hxx:73
scan_result_item()=default
Constructs an empty scan_result_item.
scan_result_item(std::string id, couchbase::cas cas, codec::encoded_value value, std::optional< std::chrono::system_clock::time_point > expiry_time, std::shared_ptr< crypto::manager > crypto_manager={})
Constructs an instance representing a single item from the result of a scan operation.
Definition scan_result_item.hxx:70
auto id() const -> const std::string &
Returns the ID of the document.
Definition scan_result_item.hxx:111
scan_result_item(std::string id)
Constructs an instance representing a single item from the result of an id-only scan operation.
Definition scan_result_item.hxx:92
bool operator==(const scan_result_item &other) const
Definition scan_result_item.hxx:98
auto id_only() const -> bool
Returns whether this scan result item only contains the document ID.
Definition scan_result_item.hxx:125
auto content_as() const -> Document
Decodes the content of the document using given codec.
Definition scan_result_item.hxx:149
auto expiry_time() const -> const std::optional< std::chrono::system_clock::time_point > &
If the document has an expiry, returns the point in time when the loaded document expires.
Definition scan_result_item.hxx:174
constexpr bool is_crypto_transcoder_v
Definition transcoder_traits.hxx:36
json_transcoder< tao_json_serializer > default_json_transcoder
Definition default_json_transcoder.hxx:28
Definition internal.hxx:27
Represents a single item from the result of scan().
Definition allow_querying_search_index_options.hxx:28
Definition encoded_value.hxx:27