Class: Couchbase::Bucket

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(backend, name) ⇒ Bucket

Returns a new instance of Bucket.

Parameters:

  • backend (Couchbase::Backend)
[View source]

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

#nameString (readonly)

Returns name of the bucket.

Returns:

  • (String)

    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

Parameters:

  • collection_name (String)

    name of the collection

Returns:

[View source]

55
56
57
# File 'lib/couchbase/bucket.rb', line 55

def collection(collection_name)
  default_scope.collection(collection_name)
end

#collectionsManagement::CollectionManager

[View source]

109
110
111
# File 'lib/couchbase/bucket.rb', line 109

def collections
  Management::CollectionManager.new(@backend, @name)
end

#default_collectionCollection

Opens the default collection for this bucket

Returns:

[View source]

62
63
64
# File 'lib/couchbase/bucket.rb', line 62

def default_collection
  Collection.new(@backend, @name, :_default, :_default)
end

#default_scopeScope

Get default scope

Returns:

[View source]

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

Returns:

  • (PingResult)
[View source]

121
# File 'lib/couchbase/bucket.rb', line 121

def ping(options = PingOptions.new) end

#scope(scope_name) ⇒ Scope

Get a named scope

Parameters:

  • scope_name (String)

    name of the scope

Returns:

[View source]

46
47
48
# File 'lib/couchbase/bucket.rb', line 46

def scope(scope_name)
  Scope.new(@backend, @name, scope_name)
end

#view_indexesManagement::ViewIndexManager

[View source]

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.

Parameters:

  • design_document_name (String)

    name of the design document

  • view_name (String)

    name of the view to query

  • options (ViewOptions) (defaults to: ViewOptions.new)

Returns:

[View source]

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, options = ViewOptions.new)
  resp = @backend.document_view(@name, design_document_name, view_name, options.namespace, {
      timeout: options.timeout,
      scan_consistency: options.scan_consistency,
      skip: options.skip,
      limit: options.limit,
      start_key: (JSON.generate(options.start_key) unless options.start_key.nil?),
      end_key: (JSON.generate(options.end_key) unless options.end_key.nil?),
      start_key_doc_id: options.start_key_doc_id,
      end_key_doc_id: options.end_key_doc_id,
      inclusive_end: options.inclusive_end,
      group: options.group,
      group_level: options.group_level,
      key: (JSON.generate(options.key) unless options.key.nil?),
      keys: (options.keys.map { |key| JSON.generate(key) } if options.keys),
      order: options.order,
      reduce: options.reduce,
      on_error: options.on_error,
      debug: options.debug,
  })
  ViewResult.new do |res|
    res. = ViewMetaData.new do |meta|
      meta.total_rows = resp[:meta][:total_rows]
      meta.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