Class: Couchbase::Bucket
- Inherits:
-
Object
- Object
- Couchbase::Bucket
- Defined in:
- lib/couchbase/bucket.rb,
lib/couchbase/view_options.rb more...
Defined Under Namespace
Classes: PingOptions, ViewMetaData, ViewOptions, ViewResult, ViewRow
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Name of the bucket.
Instance Method Summary collapse
-
#collection(collection_name) ⇒ Collection
Opens the named collection in the default scope of the bucket.
- #collections ⇒ Management::CollectionManager
-
#default_collection ⇒ Collection
Opens the default collection for this bucket.
-
#default_scope ⇒ Scope
Get default scope.
-
#initialize(backend, name) ⇒ Bucket
constructor
A new instance of Bucket.
-
#ping(options = PingOptions.new) ⇒ PingResult
Performs application-level ping requests against services in the couchbase cluster.
-
#scope(scope_name) ⇒ Scope
Get a named scope.
- #view_indexes ⇒ Management::ViewIndexManager
-
#view_query(design_document_name, view_name, options = ViewOptions.new) ⇒ ViewResult
Performs query to view index.
Constructor Details
#initialize(backend, name) ⇒ Bucket
Returns a new instance of Bucket.
28 29 30 31 32 |
# File 'lib/couchbase/bucket.rb', line 28 def initialize(backend, name) backend.open_bucket(name, true) @backend = backend @name = name end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns name of the bucket.
23 24 25 |
# File 'lib/couchbase/bucket.rb', line 23 def name @name end |
Instance Method Details
#collection(collection_name) ⇒ Collection
Opens the named collection in the default scope of the bucket
55 56 57 |
# File 'lib/couchbase/bucket.rb', line 55 def collection(collection_name) default_scope.collection(collection_name) end |
#collections ⇒ Management::CollectionManager
109 110 111 |
# File 'lib/couchbase/bucket.rb', line 109 def collections Management::CollectionManager.new(@backend, @name) end |
#default_collection ⇒ Collection
Opens the default collection for this bucket
62 63 64 |
# File 'lib/couchbase/bucket.rb', line 62 def default_collection Collection.new(@backend, @name, :_default, :_default) end |
#default_scope ⇒ Scope
Get default scope
37 38 39 |
# File 'lib/couchbase/bucket.rb', line 37 def default_scope Scope.new(@backend, @name, :_default) end |
#ping(options = PingOptions.new) ⇒ PingResult
Performs application-level ping requests against services in the couchbase cluster
121 |
# File 'lib/couchbase/bucket.rb', line 121 def ping( = PingOptions.new) end |
#scope(scope_name) ⇒ Scope
Get a named scope
46 47 48 |
# File 'lib/couchbase/bucket.rb', line 46 def scope(scope_name) Scope.new(@backend, @name, scope_name) end |
#view_indexes ⇒ Management::ViewIndexManager
114 115 116 |
# File 'lib/couchbase/bucket.rb', line 114 def view_indexes Management::ViewIndexManager.new(@backend, @name) end |
#view_query(design_document_name, view_name, options = ViewOptions.new) ⇒ ViewResult
Performs query to view index.
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 |
# File 'lib/couchbase/bucket.rb', line 73 def view_query(design_document_name, view_name, = ViewOptions.new) resp = @backend.document_view(@name, design_document_name, view_name, .namespace, { timeout: .timeout, scan_consistency: .scan_consistency, skip: .skip, limit: .limit, start_key: (JSON.generate(.start_key) unless .start_key.nil?), end_key: (JSON.generate(.end_key) unless .end_key.nil?), start_key_doc_id: .start_key_doc_id, end_key_doc_id: .end_key_doc_id, inclusive_end: .inclusive_end, group: .group, group_level: .group_level, key: (JSON.generate(.key) unless .key.nil?), keys: (.keys.map { |key| JSON.generate(key) } if .keys), order: .order, reduce: .reduce, on_error: .on_error, debug: .debug, }) ViewResult.new do |res| res. = ViewMetaData.new do || .total_rows = resp[:meta][:total_rows] .debug_info = resp[:meta][:debug_info] end res.rows = resp[:rows].map do |entry| ViewRow.new do |row| row.id = entry[:id] if entry.key?(:id) row.key = JSON.parse(entry[:key]) row.value = JSON.parse(entry[:value]) end end end end |