Class: Couchbase::Management::CollectionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/management/collection_manager.rb

Defined Under Namespace

Classes: CreateCollectionOptions, CreateScopeOptions, DropCollectionOptions, DropScopeOptions, GetAllScopesOptions, GetScopeOptions

Instance Method Summary collapse

Constructor Details

#initialize(backend, bucket_name) ⇒ CollectionManager

Returns a new instance of CollectionManager.

Parameters:

  • backend (Couchbase::Backend)
  • bucket_name (String)


24
25
26
27
# File 'lib/couchbase/management/collection_manager.rb', line 24

def initialize(backend, bucket_name)
  @backend = backend
  @bucket_name = bucket_name
end

Instance Method Details

#create_collection(collection, options = CreateCollectionOptions.new) ⇒ Object

Creates a new collection

Parameters:

Returns:

  • void

Raises:



96
97
98
# File 'lib/couchbase/management/collection_manager.rb', line 96

def create_collection(collection, options = CreateCollectionOptions.new)
  @backend.collection_create(@bucket_name, collection.scope_name, collection.name, collection.max_expiry, options.timeout)
end

#create_scope(scope_name, options = CreateScopeOptions.new) ⇒ Object

Creates a new scope

Parameters:

  • scope_name (String)

    name of the scope

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

Returns:

  • void

Raises:

  • (ArgumentError)


70
71
72
# File 'lib/couchbase/management/collection_manager.rb', line 70

def create_scope(scope_name, options = CreateScopeOptions.new)
  @backend.scope_create(@bucket_name, scope_name, options.timeout)
end

#drop_collection(collection, options = DropCollectionOptions.new) ⇒ Object

Removes a collection

Parameters:

Returns:

  • void

Raises:



108
109
110
# File 'lib/couchbase/management/collection_manager.rb', line 108

def drop_collection(collection, options = DropCollectionOptions.new)
  @backend.collection_drop(@bucket_name, collection.scope_name, collection.name, options.timeout)
end

#drop_scope(scope_name, options = DropScopeOptions.new) ⇒ Object

Removes a scope

Parameters:

  • scope_name (String)

    name of the scope

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

Returns:

  • void

Raises:



82
83
84
# File 'lib/couchbase/management/collection_manager.rb', line 82

def drop_scope(scope_name, options = DropScopeOptions.new)
  @backend.scope_drop(@bucket_name, scope_name, options.timeout)
end

#get_all_scopes(options = GetAllScopesOptions.new) ⇒ Array<ScopeSpec>

Get all scopes

Parameters:

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/couchbase/management/collection_manager.rb', line 34

def get_all_scopes(options = GetAllScopesOptions.new)
  res = @backend.scope_get_all(@bucket_name, options.timeout)
  res[:scopes].map do |s|
    ScopeSpec.new do |scope|
      scope.name = s[:name]
      scope.collections = s[:collections].map do |c|
        CollectionSpec.new do |collection|
          collection.name = c[:name]
          collection.scope_name = s[:name]
        end
      end
    end
  end
end

#get_scope(scope_name, options = GetScopeOptions.new) ⇒ ScopeSpec

Removes a scope

Parameters:

  • scope_name (String)

    name of the scope

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

Returns:

Raises:



57
58
59
60
# File 'lib/couchbase/management/collection_manager.rb', line 57

def get_scope(scope_name, options = GetScopeOptions.new)
  get_all_scopes(GetAllScopesOptions.new { |o| o.timeout = options.timeout })
    .find { |scope| scope.name == scope_name } or raise Error::ScopeNotFound, "unable to find scope #{scope_name}"
end