Module: Couchbase::Operations

Included in:
Bucket
Defined in:
lib/couchbase/operations.rb

Constant Summary collapse

RAW_JSON_DOCUMENT_CLASS =
RawJsonDocument.java_class
PERSIST_TO =
{
  :master => PersistTo::MASTER,
  0 => PersistTo::NONE,
  1 => PersistTo::ONE,
  2 => PersistTo::TWO,
  3 => PersistTo::THREE,
  4 => PersistTo::FOUR
}

Instance Method Summary collapse

Instance Method Details

#add(id, value, options = {}) ⇒ Object



35
36
37
# File 'lib/couchbase/operations.rb', line 35

def add(id, value, options = {})
  insert(id, value, options)
end

#get(id, options = {}) ⇒ Object



44
45
46
47
48
# File 'lib/couchbase/operations.rb', line 44

def get(id, options = {})
  doc = @bucket.get(id, RAW_JSON_DOCUMENT_CLASS)
  return nil if doc.nil?
  Document.new(doc)
end

#insert(id, value, options = {}) ⇒ Object



39
40
41
42
# File 'lib/couchbase/operations.rb', line 39

def insert(id, value, options = {})
  doc = doc_with_ttl(id, value, options)
  @bucket.insert(doc)
end

#remove(id) ⇒ Object



50
51
52
# File 'lib/couchbase/operations.rb', line 50

def remove(id)
  @bucket.remove(id)
end

#set(id, value, options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/couchbase/operations.rb', line 17

def set(id, value, options = {})
  if options[:persist_to]
    upsert_with_persistance(id, value, options)
  else
    upsert(id, value, options)
  end
end

#upsert(id, value, options = {}) ⇒ Object



25
26
27
28
# File 'lib/couchbase/operations.rb', line 25

def upsert(id, value, options = {})
  doc = doc_with_ttl(id, value, options)
  @bucket.upsert(doc)
end

#upsert_with_persistance(id, value, options = {}) ⇒ Object



30
31
32
33
# File 'lib/couchbase/operations.rb', line 30

def upsert_with_persistance(id, value, options = {})
  doc = doc_with_ttl(id, value, options)
  @bucket.upsert(doc, PERSIST_TO[options[:persist_to]])
end