Class: Couchbase::Protostellar::RequestGenerator::KV Private
- Inherits:
-
Object
- Object
- Couchbase::Protostellar::RequestGenerator::KV
- Defined in:
- lib/couchbase/protostellar/request_generator/kv.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- DURABILITY_LEVEL_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ :majority => :DURABILITY_LEVEL_MAJORITY, :majority_and_persist_to_active => :DURABILITY_LEVEL_MAJORITY_AND_PERSIST_TO_ACTIVE, :persist_to_majority => :DURABILITY_LEVEL_PERSIST_TO_MAJORITY, }.freeze
- LOOKUP_IN_OPERATION_TYPE_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ :get => :OPERATION_GET, :get_doc => :OPERATION_GET, :exists => :OPERATION_EXISTS, :count => :OPERATION_COUNT, }.freeze
- MUTATE_IN_OPERATION_TYPE_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ :set_doc => :OPERATION_REPLACE, :replace => :OPERATION_REPLACE, :dict_add => :OPERATION_INSERT, :remove_doc => :OPERATION_REMOVE, :remove => :OPERATION_REMOVE, :dict_upsert => :OPERATION_UPSERT, :array_push_last => :OPERATION_ARRAY_APPEND, :array_push_first => :OPERATION_ARRAY_PREPEND, :array_insert => :OPERATION_ARRAY_INSERT, :array_add_unique => :OPERATION_ARRAY_ADD_UNIQUE, :counter => :OPERATION_COUNTER, }.freeze
- MUTATE_IN_STORE_SEMANTIC_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ :replace => :STORE_SEMANTIC_REPLACE, :upsert => :STORE_SEMANTIC_UPSERT, :insert => :STORE_SEMANTIC_INSERT, }.freeze
Instance Attribute Summary collapse
- #bucket_name ⇒ Object readonly private
- #collection_name ⇒ Object readonly private
- #scope_name ⇒ Object readonly private
Instance Method Summary collapse
- #append_request(id, content, options) ⇒ Object private
- #decrement_request(id, options) ⇒ Object private
- #exists_request(id, options) ⇒ Object private
- #get_all_replicas_request(id, options) ⇒ Object private
- #get_and_lock_request(id, lock_time, options) ⇒ Object private
- #get_and_touch_request(id, expiry, options) ⇒ Object private
- #get_any_replica_request(id, options) ⇒ Object private
- #get_request(id, options) ⇒ Object private
- #increment_request(id, options) ⇒ Object private
-
#initialize(bucket_name, scope_name, collection_name) ⇒ KV
constructor
private
A new instance of KV.
- #insert_request(id, content, options) ⇒ Object private
- #location ⇒ Object private
- #lookup_in_request(id, specs, options) ⇒ Object private
- #mutate_in_request(id, specs, options) ⇒ Object private
- #prepend_request(id, content, options) ⇒ Object private
- #remove_request(id, options) ⇒ Object private
- #replace_request(id, content, options) ⇒ Object private
- #touch_request(id, expiry, options) ⇒ Object private
- #unlock_request(id, cas, options) ⇒ Object private
- #upsert_request(id, content, options) ⇒ Object private
Constructor Details
#initialize(bucket_name, scope_name, collection_name) ⇒ KV
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of KV.
67 68 69 70 71 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 67 def initialize(bucket_name, scope_name, collection_name) @bucket_name = bucket_name @scope_name = scope_name @collection_name = collection_name end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 63 def bucket_name @bucket_name end |
#collection_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 65 def collection_name @collection_name end |
#scope_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 64 def scope_name @scope_name end |
Instance Method Details
#append_request(id, content, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 314 def append_request(id, content, ) proto_opts = {} proto_opts[:cas] = .cas unless .cas.nil? proto_opts[:durability_level] = get_durability_level() unless .durability_level == :none proto_req = Generated::KV::V1::AppendRequest.new( key: id, content: content, **location, **proto_opts ) create_kv_request(proto_req, :append, ) end |
#decrement_request(id, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 297 def decrement_request(id, ) proto_opts = { delta: .delta, } expiry_type, expiry_value = get_expiry() proto_opts[expiry_type] = expiry_value unless expiry_value.nil? proto_opts[:initial] = .initial unless .initial.nil? proto_req = Generated::KV::V1::DecrementRequest.new( key: id, **location, **proto_opts ) create_kv_request(proto_req, :decrement, ) end |
#exists_request(id, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 226 def exists_request(id, ) proto_opts = {} proto_req = Generated::KV::V1::ExistsRequest.new( key: id, **proto_opts, **location ) create_kv_request(proto_req, :exists, ) end |
#get_all_replicas_request(id, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
344 345 346 347 348 349 350 351 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 344 def get_all_replicas_request(id, ) proto_req = Generated::KV::V1::GetAllReplicasRequest.new( key: id, **location ) create_kv_request(proto_req, :get_all_replicas, , idempotent: true) end |
#get_and_lock_request(id, lock_time, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
109 110 111 112 113 114 115 116 117 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 109 def get_and_lock_request(id, lock_time, ) proto_req = Generated::KV::V1::GetAndLockRequest.new( **location, key: id, lock_time: lock_time.respond_to?(:in_seconds) ? lock_time.in_seconds : lock_time ) create_kv_request(proto_req, :get_and_lock, ) end |
#get_and_touch_request(id, expiry, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 95 def get_and_touch_request(id, expiry, ) expiry_type, expiry_value = get_expiry(expiry) raise ArgumentError, "Expiry cannot be nil" if expiry_value.nil? proto_req = Generated::KV::V1::GetAndTouchRequest.new( **{expiry_type => expiry_value}, **location, key: id ) create_kv_request(proto_req, :get_and_touch, ) end |
#get_any_replica_request(id, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
353 354 355 356 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 353 def get_any_replica_request(id, ) # Uses the GetAllReplicas request and returns the first item from the result get_all_replicas_request(id, ) end |
#get_request(id, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 81 def get_request(id, ) proto_opts = { project: .projections, } proto_req = Generated::KV::V1::GetRequest.new( key: id, **location, **proto_opts ) create_kv_request(proto_req, :get, , idempotent: true) end |
#increment_request(id, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 280 def increment_request(id, ) proto_opts = { delta: .delta, } expiry_type, expiry_value = get_expiry() proto_opts[expiry_type] = expiry_value unless expiry_value.nil? proto_opts[:initial] = .initial unless .initial.nil? proto_req = Generated::KV::V1::IncrementRequest.new( key: id, **location, **proto_opts ) create_kv_request(proto_req, :increment, ) end |
#insert_request(id, content, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 165 def insert_request(id, content, ) encoded, flag = get_encoded(content, ) proto_opts = { content_flags: flag, } proto_opts[:durability_level] = get_durability_level() unless .durability_level == :none expiry_type, expiry_value = get_expiry() proto_opts[expiry_type] = expiry_value unless expiry_value.nil? proto_req = Generated::KV::V1::InsertRequest.new( key: id, content_uncompressed: encoded, **location, **proto_opts ) create_kv_request(proto_req, :insert, ) end |
#location ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
73 74 75 76 77 78 79 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 73 def location { bucket_name: @bucket_name, scope_name: @scope_name, collection_name: @collection_name, } end |
#lookup_in_request(id, specs, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 265 def lookup_in_request(id, specs, ) proto_opts = { flags: get_lookup_in_flags(), } proto_req = Generated::KV::V1::LookupInRequest.new( key: id, **location, specs: specs.map { |s| get_lookup_in_spec(s) }, **proto_opts ) create_kv_request(proto_req, :lookup_in, , idempotent: true) end |
#mutate_in_request(id, specs, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 238 def mutate_in_request(id, specs, ) if .create_as_deleted raise Error::FeatureNotAvailable, "The #{Couchbase::Protostellar::NAME} protocol does not support create_as_deleted" end proto_opts = { flags: get_mutate_in_flags(), store_semantic: get_mutate_in_store_semantic(), durability_level: get_durability_level(), } proto_opts[:cas] = .cas unless .cas.nil? unless .preserve_expiry expiry_type, expiry_value = get_expiry() proto_opts[expiry_type] = expiry_value end proto_req = Generated::KV::V1::MutateInRequest.new( key: id, **location, specs: specs.map { |s| get_mutate_in_spec(s) }, **proto_opts ) create_kv_request(proto_req, :mutate_in, ) end |
#prepend_request(id, content, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 329 def prepend_request(id, content, ) proto_opts = {} proto_opts[:cas] = .cas unless .cas.nil? proto_opts[:durability_level] = get_durability_level() unless .durability_level == :none proto_req = Generated::KV::V1::PrependRequest.new( key: id, content: content, **location, **proto_opts ) create_kv_request(proto_req, :prepend, ) end |
#remove_request(id, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 211 def remove_request(id, ) proto_opts = {} proto_opts[:cas] = .cas unless .cas.nil? proto_opts[:durability_level] = get_durability_level() unless .durability_level == :none proto_req = Generated::KV::V1::RemoveRequest.new( key: id, **location, **proto_opts ) create_kv_request(proto_req, :remove, ) end |
#replace_request(id, content, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 186 def replace_request(id, content, ) encoded, flag = get_encoded(content, ) proto_opts = { content_flags: flag, } proto_opts[:cas] = .cas unless .cas.nil? proto_opts[:durability_level] = get_durability_level() unless .durability_level == :none unless .preserve_expiry expiry_type, expiry_value = get_expiry() proto_opts[expiry_type] = expiry_value end proto_req = Generated::KV::V1::ReplaceRequest.new( key: id, content_uncompressed: encoded, **location, **proto_opts ) create_kv_request(proto_req, :replace, ) end |
#touch_request(id, expiry, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 129 def touch_request(id, expiry, ) expiry_type, expiry_value = get_expiry(expiry) raise ArgumentError, "Expiry cannot be nil" if expiry_value.nil? proto_req = Generated::KV::V1::TouchRequest.new( **{expiry_type => expiry_value}, **location, key: id ) create_kv_request(proto_req, :touch, ) end |
#unlock_request(id, cas, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 122 123 124 125 126 127 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 119 def unlock_request(id, cas, ) proto_req = Generated::KV::V1::UnlockRequest.new( **location, key: id, cas: cas ) create_kv_request(proto_req, :unlock, ) end |
#upsert_request(id, content, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/couchbase/protostellar/request_generator/kv.rb', line 143 def upsert_request(id, content, ) encoded, flag = get_encoded(content, ) proto_opts = { content_flags: flag, preserve_expiry_on_existing: .preserve_expiry, } proto_opts[:durability_level] = get_durability_level() unless .durability_level == :none expiry_type, expiry_value = get_expiry() proto_opts[expiry_type] = expiry_value proto_req = Generated::KV::V1::UpsertRequest.new( key: id, content_uncompressed: encoded, **location, **proto_opts ) create_kv_request(proto_req, :upsert, ) end |