|
virtual auto | get (const couchbase::collection &coll, const std::string &id) -> std::pair< error, transaction_get_result >=0 |
| Get a document from a collection.
|
|
virtual auto | get_replica_from_preferred_server_group (const couchbase::collection &coll, const std::string &id) -> std::pair< error, transaction_get_result >=0 |
| Get a document copy from the selected server group.
|
|
template<typename Transcoder = codec::default_json_transcoder, typename Document , std::enable_if_t<!std::is_same_v< codec::encoded_value, Document >, bool > = true> |
auto | insert (const couchbase::collection &coll, const std::string &id, const Document &content) -> std::pair< error, transaction_get_result > |
| Insert a document into a collection.
|
|
template<typename Transcoder = codec::default_json_transcoder, typename Document , std::enable_if_t<!std::is_same_v< codec::encoded_value, Document >, bool > = true> |
auto | replace (const transaction_get_result &doc, const Document &content) -> std::pair< error, transaction_get_result > |
| Replace the contents of a document in a collection.
|
|
virtual auto | remove (const transaction_get_result &doc) -> error=0 |
| Remove a document.
|
|
auto | query (const std::string &statement, const transaction_query_options &options={}) -> std::pair< error, transaction_query_result > |
| Perform an unscoped query.
|
|
auto | query (const scope &scope, const std::string &statement, const transaction_query_options &opts={}) -> std::pair< error, transaction_query_result > |
| Perform a scoped query.
|
|
virtual | ~attempt_context ()=default |
|
The attempt_context is used for all synchronous transaction operations.
In the example below, we get a document then replace its content:
auto [tx_err, tx_res] = cluster.transactions()->run(
[=](std::shared_ptr<couchbase::transactions::attempt_context> ctx) ->
couchbase::error {
auto [err_ctx, doc] = ctx->get(collection, id_1);
if (err_ctx.ec()) {
fmt::print(stderr, "failed to get document \"{}\": {}\n", id_1, err_ctx.ec().message());
return {};
}
ctx->replace(doc, tao::json::value{ { "some", "other content" } });
return {};
});
if (tx_err.ec()) {
fmt::print(stderr,
"error in transaction {}, cause: {}\n",
tx_err.ec().message(),
tx_err.cause().has_value() ? tx_err.cause().value().ec().message() : "");
retval = 1;
} else {
fmt::print("transaction {} completed successfully\n", tx_res.transaction_id);
}