Couchbase C++ SDK 1.0.4 (rev. 5355b0f)
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{
41{
42public:
49 scan_result_item() = default;
50
62 scan_result_item(std::string id,
65 std::optional<std::chrono::system_clock::time_point> expiry_time)
66 : result{ cas }
67 , id_{ std::move(id) }
68 , id_only_{ false }
69 , value_{ std::move(value) }
70 , expiry_time_{ expiry_time }
71 {
72 }
73
82 explicit scan_result_item(std::string id)
83 : id_{ std::move(id) }
84 , id_only_{ true }
85 {
86 }
87
88 bool operator==(const scan_result_item& other) const
89 {
90 return id_ == other.id_ && cas() == other.cas();
91 }
92
101 [[nodiscard]] auto id() const -> const std::string&
102 {
103 return id_;
104 }
105
115 [[nodiscard]] auto id_only() const -> bool
116 {
117 return id_only_;
118 }
119
135 template<typename Document,
136 typename Transcoder = codec::default_json_transcoder,
137 std::enable_if_t<!codec::is_transcoder_v<Document>, bool> = true,
138 std::enable_if_t<codec::is_transcoder_v<Transcoder>, bool> = true>
139 [[nodiscard]] auto content_as() const -> Document
140 {
141 if (id_only_) {
142 return {};
143 }
144 return Transcoder::template decode<Document>(value_);
145 }
146
160 [[nodiscard]] auto expiry_time() const
161 -> const std::optional<std::chrono::system_clock::time_point>&
162 {
163 return expiry_time_;
164 }
165
166private:
167 std::string id_{};
168 bool id_only_{};
169 codec::encoded_value value_{};
170 std::optional<std::chrono::system_clock::time_point> expiry_time_{};
171};
172} // 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:32
auto cas() const -> couchbase::cas
Definition result.hxx:57
Definition scan_result_item.hxx:41
scan_result_item()=default
Constructs an empty scan_result_item.
auto id() const -> const std::string &
Returns the ID of the document.
Definition scan_result_item.hxx:101
scan_result_item(std::string id, couchbase::cas cas, codec::encoded_value value, std::optional< std::chrono::system_clock::time_point > expiry_time)
Constructs an instance representing a single item from the result of a scan operation.
Definition scan_result_item.hxx:62
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:82
bool operator==(const scan_result_item &other) const
Definition scan_result_item.hxx:88
auto id_only() const -> bool
Returns whether this scan result item only contains the document ID.
Definition scan_result_item.hxx:115
auto content_as() const -> Document
Decodes the content of the document using given codec.
Definition scan_result_item.hxx:139
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:160
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
Definition encoded_value.hxx:27