forked from couchbase/couchbase-ruby-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
collection.rb
702 lines (671 loc) · 26.6 KB
/
collection.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
# Copyright 2020-2021 Couchbase, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require "couchbase/errors"
require "couchbase/collection_options"
require "couchbase/binary_collection"
require "couchbase/key_value_scan"
module Couchbase
# Provides access to all collection APIs
class Collection
attr_reader :bucket_name
attr_reader :scope_name
attr_reader :name
alias inspect to_s
# @param [Couchbase::Backend] backend
# @param [String] bucket_name name of the bucket
# @param [String] scope_name name of the scope
# @param [String] collection_name name of the collection
def initialize(backend, bucket_name, scope_name, collection_name)
@backend = backend
@bucket_name = bucket_name
@scope_name = scope_name
@name = collection_name
end
# Provides access to the binary APIs, not used for JSON documents
#
# @return [BinaryCollection]
def binary
BinaryCollection.new(self)
end
# @return [Management::CollectionQueryIndexManager]
def query_indexes
Management::CollectionQueryIndexManager.new(@backend, @bucket_name, @scope_name, @name)
end
# Fetches the full document from the collection
#
# @param [String] id the document id which is used to uniquely identify it
# @param [Options::Get] options request customization
#
# @example Get document contents
# res = collection.get("customer123")
# res.content["addresses"]
#
# # {"billing"=>
# # {"line1"=>"123 Any Street", "line2"=>"Anytown", "country"=>"United Kingdom"},
# # "delivery"=>
# # {"line1"=>"123 Any Street", "line2"=>"Anytown", "country"=>"United Kingdom"}}
#
# @example Get partial document using projections
# res = collection.get("customer123", Options::Get(projections: ["name", "addresses.billing"]))
# res.content
#
# # {"addresses"=>
# # {"billing"=>
# # {"country"=>"United Kingdom",
# # "line1"=>"123 Any Street",
# # "line2"=>"Anytown"}},
# # "name"=>"Douglas Reynholm"}
#
# @return [GetResult]
def get(id, options = Options::Get::DEFAULT)
resp = if options.need_projected_get?
@backend.document_get_projected(bucket_name, @scope_name, @name, id, options.to_backend)
else
@backend.document_get(bucket_name, @scope_name, @name, id, options.to_backend)
end
GetResult.new do |res|
res.transcoder = options.transcoder
res.cas = resp[:cas]
res.flags = resp[:flags]
res.encoded = resp[:content]
res.expiry = resp[:expiry] if resp.key?(:expiry)
end
end
# Fetches multiple documents from the collection.
#
# @note that it will not generate {Error::DocumentNotFound} exceptions in this case. The caller should check
# {GetResult#error} property of the result
#
# @param [Array<String>] ids the array of document identifiers
# @param [Options::GetMulti] options request customization
#
# @example Fetch "foo" and "bar" in a batch
# res = collection.get(["foo", "bar"], Options::GetMulti(timeout: 3_000))
# res[0].content #=> content of "foo"
# res[1].content #=> content of "bar"
#
# @return [Array<GetResult>]
def get_multi(ids, options = Options::GetMulti::DEFAULT)
resp = @backend.document_get_multi(ids.map { |id| [bucket_name, @scope_name, @name, id] }, options.to_backend)
resp.map do |entry|
GetResult.new do |res|
res.transcoder = options.transcoder
res.id = entry[:id]
res.cas = entry[:cas]
res.flags = entry[:flags]
res.encoded = entry[:content]
res.error = entry[:error]
end
end
end
# Fetches the full document and write-locks it for the given duration
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Integer, #in_seconds] lock_time how long to lock the document (values over 30 seconds will be capped)
# @param [Options::GetAndLock] options request customization
#
# @example Retrieve document and lock for 10 seconds
# collection.get_and_lock("customer123", 10, Options::GetAndLock(timeout: 3_000))
#
# @example Update document pessimistically
# res = collection.get_and_lock("customer123", 10)
# user_data = res.content
# user_data["admin"] = true
# collection.replace("user", user_data, Options::Upsert(cas: res.cas))
#
# @return [GetResult]
def get_and_lock(id, lock_time, options = Options::GetAndLock::DEFAULT)
resp = @backend.document_get_and_lock(bucket_name, @scope_name, @name, id,
lock_time.respond_to?(:in_seconds) ? lock_time.public_send(:in_seconds) : lock_time,
options.to_backend)
GetResult.new do |res|
res.transcoder = options.transcoder
res.cas = resp[:cas]
res.flags = resp[:flags]
res.encoded = resp[:content]
end
end
# Fetches a full document and resets its expiration time to the duration provided
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Integer, #in_seconds, Time] expiry the new expiration time for the document
# @param [Options::GetAndTouch] options request customization
#
# @example Retrieve document and prolong its expiration for another 10 seconds
# collection.get_and_touch("customer123", 10)
#
# @return [GetResult]
def get_and_touch(id, expiry, options = Options::GetAndTouch::DEFAULT)
resp = @backend.document_get_and_touch(bucket_name, @scope_name, @name, id,
Utils::Time.extract_expiry_time(expiry),
options.to_backend)
GetResult.new do |res|
res.transcoder = options.transcoder
res.cas = resp[:cas]
res.flags = resp[:flags]
res.encoded = resp[:content]
end
end
# Reads from all available replicas and the active node and returns the results
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Options::GetAllReplicas] options request customization
#
# @return [Array<GetReplicaResult>]
def get_all_replicas(id, options = Options::GetAllReplicas::DEFAULT)
resp = @backend.document_get_all_replicas(@bucket_name, @scope_name, @name, id, options.to_backend)
resp.map do |entry|
GetReplicaResult.new do |res|
res.transcoder = options.transcoder
res.cas = entry[:cas]
res.flags = entry[:flags]
res.encoded = entry[:content]
res.is_replica = entry[:is_replica]
end
end
end
# Reads all available replicas and active, and returns the first found.
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Options::GetAnyReplica] options request customization
#
# @example Get document contents
# res = collection.get_any_replica("customer123")
# res.is_active #=> false
# res.content["addresses"]
#
# # {"billing"=>
# # {"line1"=>"123 Any Street", "line2"=>"Anytown", "country"=>"United Kingdom"},
# # "delivery"=>
# # {"line1"=>"123 Any Street", "line2"=>"Anytown", "country"=>"United Kingdom"}}
#
#
# @return [GetReplicaResult]
def get_any_replica(id, options = Options::GetAnyReplica::DEFAULT)
resp = @backend.document_get_any_replica(@bucket_name, @scope_name, @name, id, options.to_backend)
GetReplicaResult.new do |res|
res.transcoder = options.transcoder
res.cas = resp[:cas]
res.flags = resp[:flags]
res.encoded = resp[:content]
res.is_replica = resp[:is_replica]
end
end
# Checks if the given document ID exists on the active partition.
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Options::Exists] options request customization
#
# @example Check if the document exists without fetching its contents
# res = collection.exists("customer123")
# res.exists? #=> true
#
# @return [ExistsResult]
def exists(id, options = Options::Exists::DEFAULT)
resp = @backend.document_exists(bucket_name, @scope_name, @name, id, options.to_backend)
ExistsResult.new do |res|
res.deleted = resp[:deleted]
res.exists = resp[:exists]
res.expiry = resp[:expiry]
res.flags = resp[:flags]
res.sequence_number = resp[:sequence_number]
res.datatype = resp[:datatype]
res.cas = resp[:cas]
end
end
# Removes a document from the collection
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Options::Remove] options request customization
#
# @example Remove the document in collection
# res = collection.remove("customer123")
# res.cas #=> 241994216651798
#
# @example Remove the document in collection, but apply optimistic lock
# res = collection.upsert("mydoc", {"foo" => 42})
# res.cas #=> 7751414725654
#
# begin
# res = collection.remove("mydoc", Options::Remove(cas: 3735928559))
# rescue Error::CasMismatch
# puts "Failed to remove the document, it might be changed by other application"
# end
#
# @return [MutationResult]
def remove(id, options = Options::Remove::DEFAULT)
resp = @backend.document_remove(bucket_name, @scope_name, @name, id, options.to_backend)
MutationResult.new do |res|
res.cas = resp[:cas]
res.mutation_token = extract_mutation_token(resp)
end
end
# Removes a list of the documents from the collection
#
# @note that it will not generate {Error::DocumentNotFound} or {Error::CasMismatch} exceptions in this case.
# The caller should check {MutationResult#error} property of the result
#
# @param [Array<String, Array>] ids the array of document ids, or ID/CAS pairs +[String,Integer]+
# @param [Options::RemoveMulti] options request customization
#
# @example Remove two documents in collection. For "mydoc" apply optimistic lock
# res = collection.upsert("mydoc", {"foo" => 42})
# res.cas #=> 7751414725654
#
# res = collection.remove_multi(["foo", ["mydoc", res.cas]])
# if res[1].error.is_a?(Error::CasMismatch)
# puts "Failed to remove the document, it might be changed by other application"
# end
#
# @return [Array<MutationResult>]
def remove_multi(ids, options = Options::RemoveMulti::DEFAULT)
resp = @backend.document_remove_multi(bucket_name, @scope_name, @name, ids.map do |id|
case id
when String
[id, nil]
when Array
id
else
raise ArgumentError, "id argument of remove_multi must be a String or Array<String, Integer>, given: #{id.inspect}"
end
end, options.to_backend)
resp.map do |entry|
MutationResult.new do |res|
res.cas = entry[:cas]
res.mutation_token = extract_mutation_token(entry)
res.error = entry[:error]
res.id = entry[:id]
end
end
end
# Inserts a full document which does not exist yet
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Object] content the document content to insert
# @param [Options::Insert] options request customization
#
# @example Insert new document in collection
# res = collection.insert("mydoc", {"foo" => 42}, Options::Insert(expiry: 20))
# res.cas #=> 242287264414742
#
# @example Handle error when the document already exists
# collection.exists("mydoc").exists? #=> true
# begin
# res = collection.insert("mydoc", {"foo" => 42})
# rescue Error::DocumentExists
# puts "Failed to insert the document, it already exists in the collection"
# end
#
# @return [MutationResult]
def insert(id, content, options = Options::Insert::DEFAULT)
blob, flags = options.transcoder ? options.transcoder.encode(content) : [content, 0]
resp = @backend.document_insert(bucket_name, @scope_name, @name, id, blob, flags, options.to_backend)
MutationResult.new do |res|
res.cas = resp[:cas]
res.mutation_token = extract_mutation_token(resp)
end
end
# Upserts (inserts or updates) a full document which might or might not exist yet
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Object] content the document content to upsert
# @param [Options::Upsert] options request customization
#
# @example Upsert new document in collection
# res = collection.upsert("mydoc", {"foo" => 42}, Options::Upsert(expiry: 20))
# res.cas #=> 242287264414742
#
# @return [MutationResult]
def upsert(id, content, options = Options::Upsert::DEFAULT)
blob, flags = options.transcoder ? options.transcoder.encode(content) : [content, 0]
resp = @backend.document_upsert(bucket_name, @scope_name, @name, id, blob, flags, options.to_backend)
MutationResult.new do |res|
res.cas = resp[:cas]
res.mutation_token = extract_mutation_token(resp)
end
end
# Upserts (inserts or updates) a list of documents which might or might not exist yet
#
# @note that it will not generate exceptions in this case. The caller should check {MutationResult#error} property of the
# result
#
# @param [Array<Array>] id_content array of tuples +String,Object+, where first entry treated as document key,
# and the second as value to upsert.
# @param [Options::UpsertMulti] options request customization
#
# @example Upsert two documents with IDs "foo" and "bar" into a collection
# res = collection.upsert_multi([
# "foo", {"foo" => 42},
# "bar", {"bar" => "some value"}
# ])
# res[0].cas #=> 7751414725654
# res[1].cas #=> 7751418925851
#
# @return [Array<MutationResult>]
def upsert_multi(id_content, options = Options::UpsertMulti::DEFAULT)
resp = @backend.document_upsert_multi(bucket_name, @scope_name, @name, id_content.map do |(id, content)|
blob, flags = options.transcoder ? options.transcoder.encode(content) : [content, 0]
[id, blob, flags]
end, options.to_backend)
resp.map do |entry|
MutationResult.new do |res|
res.cas = entry[:cas]
res.mutation_token = extract_mutation_token(entry)
res.error = entry[:error]
res.id = entry[:id]
end
end
end
# Replaces a full document which already exists
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Object] content the document content to upsert
# @param [Options::Replace] options request customization
#
# @example Replace new document in collection with optimistic locking
# res = collection.get("mydoc")
# res = collection.replace("mydoc", {"foo" => 42}, Options::Replace(cas: res.cas))
# res.cas #=> 242287264414742
#
# @return [MutationResult]
def replace(id, content, options = Options::Replace::DEFAULT)
blob, flags = options.transcoder ? options.transcoder.encode(content) : [content, 0]
resp = @backend.document_replace(bucket_name, @scope_name, @name, id, blob, flags, options.to_backend)
MutationResult.new do |res|
res.cas = resp[:cas]
res.mutation_token = extract_mutation_token(resp)
end
end
# Update the expiration of the document with the given id
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Integer, #in_seconds, Time] expiry new expiration time for the document
# @param [Options::Touch] options request customization
#
# @example Reset expiration timer for document to 30 seconds
# res = collection.touch("customer123", 30)
#
# @return [MutationResult]
def touch(id, expiry, options = Options::Touch::DEFAULT)
resp = @backend.document_touch(bucket_name, @scope_name, @name, id,
Utils::Time.extract_expiry_time(expiry),
options.to_backend)
MutationResult.new do |res|
res.cas = resp[:cas]
end
end
# Unlocks a document if it has been locked previously
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Integer] cas CAS value which is needed to unlock the document
# @param [Options::Unlock] options request customization
#
# @example Lock (pessimistically) and unlock document
# res = collection.get_and_lock("customer123", 10)
# collection.unlock("customer123", res.cas)
#
# @return [void]
#
# @raise [Error::DocumentNotFound]
def unlock(id, cas, options = Options::Unlock::DEFAULT)
@backend.document_unlock(bucket_name, @scope_name, @name, id, cas, options.to_backend)
end
# Performs lookups to document fragments
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Array<LookupInSpec>] specs the list of specifications which describe the types of the lookups to perform
# @param [Options::LookupIn] options request customization
#
# @example Get list of IDs of completed purchases
# lookup_specs = [
# LookupInSpec::get("purchases.complete")
# ]
# collection.lookup_in("customer123", lookup_specs)
#
# @example Retrieve country name and check if pending purchases array is empty
# collection.lookup_in "customer123", [
# LookupInSpec.get("addresses.delivery.country"),
# LookupInSpec.exists("purchases.pending[-1]"),
# ]
# @return [LookupInResult]
def lookup_in(id, specs, options = Options::LookupIn::DEFAULT)
resp = @backend.document_lookup_in(
bucket_name, @scope_name, @name, id,
specs.map do |s|
{
opcode: s.type,
xattr: s.xattr?,
path: s.path,
}
end, options.to_backend
)
LookupInResult.new do |res|
res.transcoder = options.transcoder
res.cas = resp[:cas]
res.deleted = resp[:deleted]
res.encoded = resp[:fields].map do |field|
SubDocumentField.new do |f|
f.exists = field[:exists]
f.index = field[:index]
f.path = field[:path]
f.value = field[:value]
f.error = field[:error]
end
end
end
end
# Performs lookups to document fragments. Reads from the active node and all available replicas and returns the
# first result found
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Array<LookupInSpec>] specs the list of specifications which describe the types of the lookups to perform
# @param [Options::LookupInAnyReplica] options request customization
#
# @return [LookupInReplicaResult]
#
# @raise [Error::DocumentIrretrievable]
# @raise [Error::Timeout]
# @raise [Error::CouchbaseError]
# @raise [Error::FeatureNotAvailable]
def lookup_in_any_replica(id, specs, options = Options::LookupInAnyReplica::DEFAULT)
resp = @backend.document_lookup_in_any_replica(
bucket_name, @scope_name, @name, id,
specs.map do |s|
{
opcode: s.type,
xattr: s.xattr?,
path: s.path,
}
end, options.to_backend
)
extract_lookup_in_replica_result(resp, options)
end
# Performs lookups to document fragments. Reads from the active node and all available replicas and returns all of
# the results
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Array<LookupInSpec>] specs the list of specifications which describe the types of the lookups to perform
# @param [Options::LookupInAllReplicas] options request customization
#
# @return [Array<LookupInReplicaResult>]
#
# @raise [Error::DocumentNotFound]
# @raise [Error::Timeout]
# @raise [Error::CouchbaseError]
# @raise [Error::FeatureNotAvailable]
def lookup_in_all_replicas(id, specs, options = Options::LookupInAllReplicas::DEFAULT)
resp = @backend.document_lookup_in_all_replicas(
bucket_name, @scope_name, @name, id,
specs.map do |s|
{
opcode: s.type,
xattr: s.xattr?,
path: s.path,
}
end, options.to_backend
)
resp.map do |entry|
extract_lookup_in_replica_result(entry, options)
end
end
# Performs mutations to document fragments
#
# @param [String] id the document id which is used to uniquely identify it.
# @param [Array<MutateInSpec>] specs the list of specifications which describe the types of the lookups to perform
# @param [Options::MutateIn] options request customization
#
# @example Append number into subarray of the document
# mutation_specs = [
# MutateInSpec::array_append("purchases.complete", [42])
# ]
# collection.mutate_in("customer123", mutation_specs, Options::MutateIn(expiry: 10))
#
# @example Write meta attribute, remove array entry and replace email field
# collection.mutate_in("customer123", [
# MutateInSpec.upsert("_framework.model_type", "Customer").xattr,
# MutateInSpec.remove("addresses.billing[2]"),
# MutateInSpec.replace("email", "dougr96@hotmail.com"),
# ])
#
# @return [MutateInResult]
def mutate_in(id, specs, options = Options::MutateIn::DEFAULT)
resp = @backend.document_mutate_in(
bucket_name, @scope_name, @name, id,
specs.map do |s|
{
opcode: s.type,
path: s.path,
param: s.param,
xattr: s.xattr?,
expand_macros: s.expand_macros?,
create_path: s.create_path?,
}
end, options.to_backend
)
MutateInResult.new do |res|
res.transcoder = options.transcoder
res.cas = resp[:cas]
res.deleted = resp[:deleted]
res.mutation_token = extract_mutation_token(resp)
res.encoded = resp[:fields].map do |field|
SubDocumentField.new do |f|
f.index = field[:index]
f.path = field[:path]
f.value = field[:value]
end
end
end
end
# Performs a key-value scan operation on the collection
#
# @api uncommitted
#
# @param [RangeScan, PrefixScan, SamplingScan] scan_type the type of the scan
# @param [Options::Scan] options request customization
#
# @example Get a sample of up to 5 documents from the collection and store their IDs in an array
# result = collection.scan(SamplingScan.new(5), Options::Scan.new(ids_only: true))
# ids = result.map { |item| item.id }
#
# @example Get all documents whose ID starts with 'customer_1' and output their content
# result = collection.scan(PrefixScan.new("customer_1"))
# result.each { |item| puts item.content }
#
# @example Get all documents with ID between 'customer_1' and 'customer_2', excluding 'customer_2' and output their content
# result = collection.scan(RangeScan.new(
# from: ScanTerm.new("customer_1"),
# to: ScanTerm.new("customer_2", exclusive: true)
# ))
# result.each { |item| puts item.content }
#
# @return [ScanResults]
def scan(scan_type, options = Options::Scan::DEFAULT)
ScanResults.new(
core_scan_result: @backend.document_scan_create(
@bucket_name, @scope_name, @name, scan_type.to_backend, options.to_backend
),
transcoder: options.transcoder
)
end
private
def extract_mutation_token(resp)
return unless resp.key?(:mutation_token)
MutationToken.new do |token|
token.partition_id = resp[:mutation_token][:partition_id]
token.partition_uuid = resp[:mutation_token][:partition_uuid]
token.sequence_number = resp[:mutation_token][:sequence_number]
token.bucket_name = resp[:mutation_token][:bucket_name]
end
end
def extract_lookup_in_replica_result(resp, options)
LookupInReplicaResult.new do |res|
res.transcoder = options.transcoder
res.cas = resp[:cas]
res.deleted = resp[:deleted]
res.is_replica = resp[:is_replica]
res.encoded = resp[:fields].map do |field|
SubDocumentField.new do |f|
f.exists = field[:exists]
f.index = field[:index]
f.path = field[:path]
f.value = field[:value]
f.error = field[:error]
end
end
end
end
# @api private
# TODO: deprecate in 3.1
GetOptions = ::Couchbase::Options::Get
# @api private
# TODO: deprecate in 3.1
GetAndLockOptions = ::Couchbase::Options::GetAndLock
# @api private
# TODO: deprecate in 3.1
GetAndTouchOptions = ::Couchbase::Options::GetAndTouch
# @api private
# TODO: deprecate in 3.1
LookupInOptions = ::Couchbase::Options::LookupIn
# @api private
# TODO: deprecate in 3.1
MutateInOptions = ::Couchbase::Options::MutateIn
# @api private
# TODO: deprecate in 3.1
UnlockOptions = ::Couchbase::Options::Unlock
# @api private
# TODO: deprecate in 3.1
TouchOptions = ::Couchbase::Options::Touch
# @api private
# TODO: deprecate in 3.1
ReplaceOptions = ::Couchbase::Options::Replace
# @api private
# TODO: deprecate in 3.1
UpsertOptions = ::Couchbase::Options::Upsert
# @api private
# TODO: deprecate in 3.1
InsertOptions = ::Couchbase::Options::Insert
# @api private
# TODO: deprecate in 3.1
RemoveOptions = ::Couchbase::Options::Remove
# @api private
# TODO: deprecate in 3.1
ExistsOptions = ::Couchbase::Options::Exists
# @api private
# TODO: deprecate in 3.1
GetAnyReplicaOptions = ::Couchbase::Options::GetAnyReplica
# @api private
# TODO: deprecate in 3.1
GetAllReplicasOptions = ::Couchbase::Options::GetAllReplicas
end
end