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
- #add(id, value, options = {}) ⇒ Object
- #get(id, options = {}) ⇒ Object
- #insert(id, value, options = {}) ⇒ Object
- #remove(id) ⇒ Object
- #set(id, value, options = {}) ⇒ Object
- #upsert(id, value, options = {}) ⇒ Object
- #upsert_with_persistance(id, value, options = {}) ⇒ Object
Instance Method Details
#add(id, value, options = {}) ⇒ Object
35 36 37 |
# File 'lib/couchbase/operations.rb', line 35 def add(id, value, = {}) insert(id, value, ) end |
#get(id, options = {}) ⇒ Object
44 45 46 47 48 |
# File 'lib/couchbase/operations.rb', line 44 def get(id, = {}) 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, = {}) doc = doc_with_ttl(id, value, ) @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, = {}) if [:persist_to] upsert_with_persistance(id, value, ) else upsert(id, value, ) end end |
#upsert(id, value, options = {}) ⇒ Object
25 26 27 28 |
# File 'lib/couchbase/operations.rb', line 25 def upsert(id, value, = {}) doc = doc_with_ttl(id, value, ) @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, = {}) doc = doc_with_ttl(id, value, ) @bucket.upsert(doc, PERSIST_TO[[:persist_to]]) end |