lib/couchbase/collection.rb in couchbase-3.2.0 vs lib/couchbase/collection.rb in couchbase-3.3.0
- old
+ new
@@ -25,12 +25,12 @@
alias inspect to_s
# @param [Couchbase::Backend] backend
# @param [String] bucket_name name of the bucket
- # @param [String, :_default] scope_name name of the scope
- # @param [String, :_default] collection_name name of the collection
+ # @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
@@ -69,13 +69,13 @@
# # "name"=>"Douglas Reynholm"}
#
# @return [GetResult]
def get(id, options = Options::Get.new)
resp = if options.need_projected_get?
- @backend.document_get_projected(bucket_name, "#{@scope_name}.#{@name}", id, options.to_backend)
+ @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)
+ @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]
@@ -97,12 +97,11 @@
# res[0].content #=> content of "foo"
# res[1].content #=> content of "bar"
#
# @return [Array<GetResult>]
def get_multi(ids, options = Options::GetMulti.new)
- collection_spec = "#{@scope_name}.#{@name}"
- resp = @backend.document_get_multi(ids.map { |id| [bucket_name, collection_spec, id] }, options.to_backend)
+ 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.cas = entry[:cas]
res.flags = entry[:flags]
@@ -127,11 +126,11 @@
# 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.new)
- resp = @backend.document_get_and_lock(bucket_name, "#{@scope_name}.#{@name}", id,
+ 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]
@@ -149,11 +148,11 @@
# @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.new)
- resp = @backend.document_get_and_touch(bucket_name, "#{@scope_name}.#{@name}", id,
+ 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]
@@ -187,15 +186,19 @@
# res = collection.exists("customer123")
# res.exists? #=> true
#
# @return [ExistsResult]
def exists(id, options = Options::Exists.new)
- resp = @backend.document_exists(bucket_name, "#{@scope_name}.#{@name}", id, options.to_backend)
+ resp = @backend.document_exists(bucket_name, @scope_name, @name, id, options.to_backend)
ExistsResult.new do |res|
- res.status = resp[:status]
- res.partition_id = resp[:partition_id]
- res.cas = resp[:cas] if res.status != :not_found
+ 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
#
@@ -216,11 +219,11 @@
# puts "Failed to remove the document, it might be changed by other application"
# end
#
# @return [MutationResult]
def remove(id, options = Options::Remove.new)
- resp = @backend.document_remove(bucket_name, "#{@scope_name}.#{@name}", id, options.to_backend)
+ 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
@@ -242,17 +245,16 @@
# puts "Failed to remove the document, it might be changed by other application"
# end
#
# @return [Array<MutationResult>]
def remove_multi(ids, options = Options::RemoveMulti.new)
- collection_spec = "#{@scope_name}.#{@name}"
resp = @backend.document_remove_multi(ids.map do |id|
case id
when String
- [bucket_name, collection_spec, id, nil]
+ [bucket_name, @scope_name, @name, id, nil]
when Array
- [bucket_name, collection_spec, id[0], id[1]]
+ [bucket_name, @scope_name, @name, id[0], id[1]]
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|
@@ -283,11 +285,11 @@
# end
#
# @return [MutationResult]
def insert(id, content, options = Options::Insert.new)
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)
+ 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
@@ -303,11 +305,11 @@
# res.cas #=> 242287264414742
#
# @return [MutationResult]
def upsert(id, content, options = Options::Upsert.new)
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)
+ 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
@@ -329,14 +331,13 @@
# res[0].cas #=> 7751414725654
# res[1].cas #=> 7751418925851
#
# @return [Array<MutationResult>]
def upsert_multi(id_content, options = Options::UpsertMulti.new)
- collection_spec = "#{@scope_name}.#{@name}"
resp = @backend.document_upsert_multi(id_content.map do |(id, content)|
blob, flags = options.transcoder ? options.transcoder.encode(content) : [content, 0]
- [bucket_name, collection_spec, id, blob, flags]
+ [bucket_name, @scope_name, @name, 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)
@@ -357,11 +358,11 @@
# res.cas #=> 242287264414742
#
# @return [MutationResult]
def replace(id, content, options = Options::Replace.new)
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)
+ 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
@@ -375,11 +376,11 @@
# @example Reset expiration timer for document to 30 seconds
# res = collection.touch("customer123", 30)
#
# @return [MutationResult]
def touch(id, expiry, options = Options::Touch.new)
- resp = @backend.document_touch(bucket_name, "#{@scope_name}.#{@name}", id,
+ 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
@@ -397,11 +398,11 @@
#
# @return [void]
#
# @raise [Error::DocumentNotFound]
def unlock(id, cas, options = Options::Unlock.new)
- @backend.document_unlock(bucket_name, "#{@scope_name}.#{@name}", id, cas, options.to_backend)
+ @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.
@@ -420,11 +421,11 @@
# LookupInSpec.exists("purchases.pending[-1]"),
# ]
# @return [LookupInResult]
def lookup_in(id, specs, options = Options::LookupIn.new)
resp = @backend.document_lookup_in(
- bucket_name, "#{@scope_name}.#{@name}", id,
+ bucket_name, @scope_name, @name, id,
specs.map do |s|
{
opcode: s.type,
xattr: s.xattr?,
path: s.path,
@@ -469,10 +470,10 @@
# ])
#
# @return [MutateInResult]
def mutate_in(id, specs, options = Options::MutateIn.new)
resp = @backend.document_mutate_in(
- bucket_name, "#{@scope_name}.#{@name}", id,
+ bucket_name, @scope_name, @name, id,
specs.map do |s|
{
opcode: s.type,
path: s.path,
param: s.param,