@@ -924,7 +924,7 @@ cb_map_error_code(const couchbase::key_value_error_context& ctx, const std::stri
924924{
925925 VALUE exc = cb_map_error_code (ctx.ec (), message);
926926 VALUE error_context = rb_hash_new ();
927- std::string error (fmt::format ( " {}, {} " , ctx.ec ().value (), ctx. ec (). message () ));
927+ std::string error (ctx.ec ().message ());
928928 rb_hash_aset (error_context, rb_id2sym (rb_intern (" error" )), cb_str_new (error));
929929 rb_hash_aset (error_context, rb_id2sym (rb_intern (" id" )), cb_str_new (ctx.id ()));
930930 rb_hash_aset (error_context, rb_id2sym (rb_intern (" scope" )), cb_str_new (ctx.scope ()));
@@ -2135,6 +2135,95 @@ cb_Backend_document_get(VALUE self, VALUE bucket, VALUE scope, VALUE collection,
21352135 return Qnil;
21362136}
21372137
2138+ struct passthrough_transcoder {
2139+ using document_type = couchbase::codec::encoded_value;
2140+
2141+ static auto decode (const couchbase::codec::encoded_value& data) -> document_type
2142+ {
2143+ return data;
2144+ }
2145+ };
2146+
2147+ template <>
2148+ struct couchbase ::codec::is_transcoder<passthrough_transcoder> : public std::true_type {
2149+ };
2150+
2151+ static VALUE
2152+ cb_Backend_document_get_any_replica (VALUE self, VALUE bucket, VALUE scope, VALUE collection, VALUE id, VALUE options)
2153+ {
2154+ const auto & core = cb_backend_to_cluster (self);
2155+
2156+ Check_Type (bucket, T_STRING);
2157+ Check_Type (scope, T_STRING);
2158+ Check_Type (collection, T_STRING);
2159+ Check_Type (id, T_STRING);
2160+
2161+ try {
2162+ couchbase::get_any_replica_options opts;
2163+ cb_options_set_timeout (opts, options);
2164+
2165+ auto f = couchbase::cluster (core)
2166+ .bucket (cb_string_new (bucket))
2167+ .scope (cb_string_new (scope))
2168+ .collection (cb_string_new (collection))
2169+ .get_any_replica (cb_string_new (id), opts);
2170+ auto [ctx, resp] = cb_wait_for_future (f);
2171+ if (ctx.ec ()) {
2172+ cb_throw_error_code (ctx, " unable to get replica of the document" );
2173+ }
2174+
2175+ auto value = resp.content_as <passthrough_transcoder>();
2176+ VALUE res = rb_hash_new ();
2177+ rb_hash_aset (res, rb_id2sym (rb_intern (" content" )), cb_str_new (value.data ));
2178+ rb_hash_aset (res, rb_id2sym (rb_intern (" cas" )), cb_cas_to_num (resp.cas ()));
2179+ rb_hash_aset (res, rb_id2sym (rb_intern (" flags" )), UINT2NUM (value.flags ));
2180+ return res;
2181+ } catch (const ruby_exception& e) {
2182+ rb_exc_raise (e.exception_object ());
2183+ }
2184+ return Qnil;
2185+ }
2186+
2187+ static VALUE
2188+ cb_Backend_document_get_all_replicas (VALUE self, VALUE bucket, VALUE scope, VALUE collection, VALUE id, VALUE options)
2189+ {
2190+ const auto & core = cb_backend_to_cluster (self);
2191+
2192+ Check_Type (bucket, T_STRING);
2193+ Check_Type (scope, T_STRING);
2194+ Check_Type (collection, T_STRING);
2195+ Check_Type (id, T_STRING);
2196+
2197+ try {
2198+ couchbase::get_all_replicas_options opts;
2199+ cb_options_set_timeout (opts, options);
2200+
2201+ auto f = couchbase::cluster (core)
2202+ .bucket (cb_string_new (bucket))
2203+ .scope (cb_string_new (scope))
2204+ .collection (cb_string_new (collection))
2205+ .get_all_replicas (cb_string_new (id), opts);
2206+ auto [ctx, resp] = cb_wait_for_future (f);
2207+ if (ctx.ec ()) {
2208+ cb_throw_error_code (ctx, " unable to get all replicas for the document" );
2209+ }
2210+
2211+ VALUE res = rb_ary_new_capa (static_cast <long >(resp.size ()));
2212+ for (const auto & entry : resp) {
2213+ VALUE response = rb_hash_new ();
2214+ auto value = entry.content_as <passthrough_transcoder>();
2215+ rb_hash_aset (response, rb_id2sym (rb_intern (" content" )), cb_str_new (value.data ));
2216+ rb_hash_aset (response, rb_id2sym (rb_intern (" cas" )), cb_cas_to_num (entry.cas ()));
2217+ rb_hash_aset (response, rb_id2sym (rb_intern (" flags" )), UINT2NUM (value.flags ));
2218+ rb_ary_push (res, response);
2219+ }
2220+ return res;
2221+ } catch (const ruby_exception& e) {
2222+ rb_exc_raise (e.exception_object ());
2223+ }
2224+ return Qnil;
2225+ }
2226+
21382227static VALUE
21392228cb_Backend_document_get_multi (VALUE self, VALUE keys, VALUE options)
21402229{
@@ -7671,6 +7760,8 @@ init_backend(VALUE mCouchbase)
76717760 rb_define_method (cBackend, " ping" , VALUE_FUNC (cb_Backend_ping), 2 );
76727761
76737762 rb_define_method (cBackend, " document_get" , VALUE_FUNC (cb_Backend_document_get), 5 );
7763+ rb_define_method (cBackend, " document_get_any_replica" , VALUE_FUNC (cb_Backend_document_get_any_replica), 5 );
7764+ rb_define_method (cBackend, " document_get_all_replicas" , VALUE_FUNC (cb_Backend_document_get_all_replicas), 5 );
76747765 rb_define_method (cBackend, " document_get_multi" , VALUE_FUNC (cb_Backend_document_get_multi), 2 );
76757766 rb_define_method (cBackend, " document_get_projected" , VALUE_FUNC (cb_Backend_document_get_projected), 5 );
76767767 rb_define_method (cBackend, " document_get_and_lock" , VALUE_FUNC (cb_Backend_document_get_and_lock), 6 );
0 commit comments