Couchbase C++ SDK 1.0.2 (rev. 51f4775)
Loading...
Searching...
No Matches
get_result Class Reference

Represents result of collection::get. More...

#include <couchbase/get_result.hxx>

Inheritance diagram for get_result:
Inheritance graph

Public Member Functions

 get_result ()=default
 
 get_result (couchbase::cas cas, codec::encoded_value value, std::optional< std::chrono::system_clock::time_point > expiry_time)
 Constructs result for get operation.
 
template<typename Document , typename Transcoder = codec::default_json_transcoder, std::enable_if_t<!codec::is_transcoder_v< Document >, bool > = true, std::enable_if_t< codec::is_transcoder_v< Transcoder >, bool > = true>
auto content_as () const -> Document
 Decodes content of the document using given codec.
 
template<typename Transcoder , std::enable_if_t< codec::is_transcoder_v< Transcoder >, bool > = true>
auto content_as () const -> typename Transcoder::document_type
 Decodes content of the document using given codec.
 
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.
 
- Public Member Functions inherited from result
 result ()=default
 
 result (couchbase::cas cas)
 
auto cas () const -> couchbase::cas
 

Detailed Description

Represents result of collection::get.

Since
1.0.0
Committed
Generally available API and should be preferred in production

Constructor & Destructor Documentation

◆ get_result() [1/2]

get_result ( )
default
Since
1.0.0
Internal
Internal interface

◆ get_result() [2/2]

get_result ( couchbase::cas cas,
codec::encoded_value value,
std::optional< std::chrono::system_clock::time_point > expiry_time )
inline

Constructs result for get operation.

Parameters
cas
valueraw document contents along with flags describing its structure
expiry_timeoptional point in time when the document will expire
Since
1.0.0
Committed
Generally available API and should be preferred in production

Member Function Documentation

◆ content_as() [1/2]

template<typename Document , typename Transcoder = codec::default_json_transcoder, std::enable_if_t<!codec::is_transcoder_v< Document >, bool > = true, std::enable_if_t< codec::is_transcoder_v< Transcoder >, bool > = true>
auto content_as ( ) const -> Document
inlinenodiscard

Decodes content of the document using given codec.

Template Parameters
Documentcustom type that Transcoder returns
Transcodertype that has static function decode that takes codec::encoded_value and returns Document
Returns
decoded document content
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ content_as() [2/2]

template<typename Transcoder , std::enable_if_t< codec::is_transcoder_v< Transcoder >, bool > = true>
auto content_as ( ) const -> typename Transcoder::document_type
inlinenodiscard

Decodes content of the document using given codec.

Template Parameters
Transcodertype that has static function decode that takes codec::encoded_value and returns Transcoder::value_type
Returns
decoded document content
Get flags and value as they are stored in the result
Here is an example of custom transcoder, that just extracts value and flags as they are stored in the result.
struct smuggling_transcoder {
using document_type = std::pair<std::vector<std::byte>, std::uint32_t>;
static auto decode(const couchbase::codec::encoded_value& encoded) -> document_type
{
return { encoded.data, encoded.flags };
}
};
template<>
struct couchbase::codec::is_transcoder<smuggling_transcoder> : public std::true_type {
};
Usage
auto [data, flags] = result.content_as<smuggling_transcoder>();
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ expiry_time()

auto expiry_time ( ) const -> const std::optional<std::chrono::system_clock::time_point>&
inlinenodiscard

If the document has an expiry, returns the point in time when the loaded document expires.

Note
This method always returns an empty std::optional unless the collection#get() request was made using get_options#with_expiry() set to true.
Returns
expiry time if present
Since
1.0.0
Committed
Generally available API and should be preferred in production

The documentation for this class was generated from the following file: