transactions-cxx  1.0.0.beta.1
transactions-cxx Documentation

A transaction consists of a lambda containing all the operations you wish to perform. The transactions object yields a arrempt_context which you use for those operations. For example:

cluster c("couchbase://", "Administrator", "password");
transaction_config config;
auto b = cluster.bucket("default");
auto coll = b->default_collection();
transactions txn(c, config);
try {[&](transactions::attempt_context& ctx) {
ctx.upsert(coll, "somekey", nlohmann::json::parse("{\"a\":\"thing\"}"));
ctx.insert(coll, "someotherkey", nlohmann::json::parse("{"\a\":\"different thing\"}"));
cout << "txn successful" << endl;
} catch (const transaction_failed& failed) {
cerr << "txn failed: " << failed.what() << endl;
} catch (const transaction_expired& expired) {
cerr << "txn timed out" << expired.what() << endl;

this upserts a document, and inserts another into the default collection in the bucket named "default". If unsuccessful, it outputs some information about what the issue was.

For a much mor detailed example, see examples/game_server.cxx