25 #include <couchbase/support.hxx> 38 enum class store_operation { upsert, insert, replace };
41 store_impl(collection* coll, store_operation op,
const std::string&
id,
const std::string& payload, uint64_t cas, durability_level level);
53 std::weak_ptr<bucket> bucket_;
54 std::chrono::microseconds kv_timeout_;
55 static const std::string DEFAULT;
59 const std::string&
id,
60 const std::string& payload,
63 std::chrono::microseconds timeout);
65 template<
typename Content>
66 result store(store_operation operation,
67 const std::string&
id,
71 std::chrono::microseconds timeout)
73 nlohmann::json j = value;
74 std::string payload = j.dump();
75 return store_impl(
this, operation,
id, payload, cas, level, timeout);
78 std::unique_ptr<pool<lcb_st*>>& instance_pool()
80 return bucket_.lock()->instance_pool_;
82 result wrap_call_for_retry(std::chrono::microseconds timeout, std::function<
result(std::chrono::microseconds)> fn);
86 static void install_callbacks(lcb_st* lcb);
90 return (name_ != bucket::default_name || scope_ != bucket::default_name);
126 template<
typename Content>
129 return wrap_call_for_retry(boost::get_optional_value_or(opts.timeout(),
default_kv_timeout()),
130 [&](std::chrono::microseconds timeout) ->
result {
131 return store(store_operation::upsert,
134 boost::get_optional_value_or(opts.cas(), 0),
135 boost::get_optional_value_or(opts.durability(), durability_level::none),
151 template<
typename Content>
154 return wrap_call_for_retry(
155 boost::get_optional_value_or(opts.timeout(),
default_kv_timeout()), [&](std::chrono::microseconds timeout) ->
result {
157 store_operation::insert,
id, value, 0, boost::get_optional_value_or(opts.durability(), durability_level::none), timeout);
173 template<
typename Content>
176 return wrap_call_for_retry(boost::get_optional_value_or(opts.timeout(),
default_kv_timeout()),
177 [&](std::chrono::microseconds timeout) ->
result {
178 return store(store_operation::replace,
181 boost::get_optional_value_or(opts.cas(), 0),
182 boost::get_optional_value_or(opts.durability(), durability_level::none),
230 CB_NODISCARD
const std::string&
name()
const 240 CB_NODISCARD
const std::string&
scope()
const 252 return bucket_.lock()->name();
262 return bucket_.lock();
result mutate_in(const std::string &id, std::vector< mutate_in_spec > specs, const mutate_in_options &opts=mutate_in_options())
Mutate some elements of a document.
CB_NODISCARD std::shared_ptr< couchbase::bucket > get_bucket()
Get bucket for this collection.
Definition: collection.hxx:260
Options for collection::insert()
Definition: options.hxx:222
Exposes bucket-level operations and collections accessors.
Definition: bucket.hxx:45
Definition: bucket.hxx:33
Options for collection::remove()
Definition: options.hxx:215
result insert(const std::string &id, const Content &value, const insert_options &opts=insert_options())
Insert document.
Definition: collection.hxx:152
result exists(const std::string &id, const exists_options &opts=exists_options())
Test existence of a document.
The result of an operation on a cluster.
Definition: result.hxx:113
result lookup_in(const std::string &id, std::vector< lookup_in_spec > specs, const lookup_in_options &opts=lookup_in_options())
Lookup some elements of a document.
Options for collection::exists()
Definition: options.hxx:194
result replace(const std::string &id, const Content &value, const replace_options &opts=replace_options())
Replace document.
Definition: collection.hxx:174
Options for collection::upsert()
Definition: options.hxx:201
CB_NODISCARD const std::string & name() const
Get name of collection.
Definition: collection.hxx:230
Options for collection::get()
Definition: options.hxx:153
Options for collection::lookup_in()
Definition: options.hxx:229
CB_NODISCARD const std::string & bucket_name() const
Get name of bucket for this collection.
Definition: collection.hxx:250
durability_level
KV Write Durability.
Definition: options.hxx:38
result upsert(const std::string &id, const Content &value, const upsert_options &opts=upsert_options())
Upsert document.
Definition: collection.hxx:127
CB_NODISCARD const std::string & scope() const
Name of scope for this collection.
Definition: collection.hxx:240
Options for collection::replace()
Definition: options.hxx:208
Exposes collection-level kv operations.
Definition: collection.hxx:46
Options for collection::mutate_in()
Definition: options.hxx:265
CB_NODISCARD std::chrono::microseconds default_kv_timeout() const
Return default timeout for the kv operations.
Definition: collection.hxx:271