Class: Couchbase::Management::CollectionManager

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/couchbase/management/collection_manager.rb,
/code/couchbase-ruby-client/lib/couchbase/management/collection_manager.rb

Defined Under Namespace

Classes: 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)


201
202
203
204
# File 'lib/couchbase/management/collection_manager.rb', line 201

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

Instance Method Details

#create_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT) ⇒ Object #create_collection(collection, options = Options::Collection::CreateCollection) ⇒ Object

Creates a new collection

Overloads:

  • #create_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT) ⇒ Object

    options = Options::Collection::CreateCollection::DEFAULT)

    @param [String] scope_name the name of the scope the collection will be created in
    @param [String] collection_name the name of the collection to be created
    @param [CreateCollectionSettings] settings settings for the new collection
    @param [Options::Collection::CreateCollection] options
    
  • #create_collection(collection, options = Options::Collection::CreateCollection) ⇒ Object
    Deprecated.

    Use #create_collection(scope_name, collection_name, settings, options) instead

    Parameters:

Returns:

  • void

Raises:



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/couchbase/management/collection_manager.rb', line 288

def create_collection(*args)
  if args[0].is_a?(CollectionSpec)
    collection = args[0]
    options = args[1] || Options::Collection::CreateCollection::DEFAULT
    settings = CreateCollectionSettings.new(max_expiry: collection.max_expiry, history: collection.history)

    warn "Calling create_collection with a CollectionSpec object has been deprecated, supply scope name, " \
         "collection name and optionally a CreateCollectionSettings instance"

    @backend.collection_create(@bucket_name, collection.scope_name, collection.name, settings.to_backend, options.to_backend)
  else
    scope_name = args[0]
    collection_name = args[1]
    settings = args[2] || CreateCollectionSettings::DEFAULT
    options = args[3] || Options::Collection::CreateCollection::DEFAULT
    @backend.collection_create(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend)
  end
end

#create_scope(scope_name, options = Options::Collection::CreateScope.new) ⇒ Object

Creates a new scope

Parameters:

Returns:

  • void

Raises:

  • (ArgumentError)


253
254
255
# File 'lib/couchbase/management/collection_manager.rb', line 253

def create_scope(scope_name, options = Options::Collection::CreateScope.new)
  @backend.scope_create(@bucket_name, scope_name, options.to_backend)
end

#drop_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT) ⇒ Object #drop_collection(collection, options = Options::Collection::CreateCollection) ⇒ Object

Removes a collection

Overloads:

  • #drop_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT) ⇒ Object

    options = Options::Collection::CreateCollection::DEFAULT)

    Parameters:

    • scope_name (String)

      the name of the scope the collection is in

    • collection_name (String)

      the name of the collection to be removed

  • #drop_collection(collection, options = Options::Collection::CreateCollection) ⇒ Object
    Deprecated.

    Use #drop_collection(scope_name, collection_name, options) instead

    Parameters:

Returns:

  • void

Raises:



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/couchbase/management/collection_manager.rb', line 338

def drop_collection(*args)
  if args[0].is_a?(CollectionSpec)
    collection = args[0]
    options = args[1] || Options::Collection::CreateCollection::DEFAULT

    warn "Calling drop_collection with a CollectionSpec object has been deprecated, supply scope name and collection name"

    @backend.collection_drop(@bucket_name, collection.scope_name, collection.name, options.to_backend)
  else
    scope_name = args[0]
    collection_name = args[1]
    options = args[2] || Options::Collection::CreateCollection::DEFAULT
    @backend.collection_drop(@bucket_name, scope_name, collection_name, options.to_backend)
  end
end

#drop_scope(scope_name, options = Options::Collection::DropScope.new) ⇒ Object

Removes a scope

Parameters:

Returns:

  • void

Raises:



265
266
267
# File 'lib/couchbase/management/collection_manager.rb', line 265

def drop_scope(scope_name, options = Options::Collection::DropScope.new)
  @backend.scope_drop(@bucket_name, scope_name, options.to_backend)
end

#get_all_scopes(options = Options::Collection::GetAllScopes.new) ⇒ Array<ScopeSpec>

Get all scopes

Parameters:

Returns:



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/couchbase/management/collection_manager.rb', line 211

def get_all_scopes(options = Options::Collection::GetAllScopes.new)
  res = @backend.scope_get_all(@bucket_name, options.to_backend)
  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]
          collection.max_expiry = c[:max_expiry]
          collection.history = c[:history]
        end
      end
    end
  end
end

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

Deprecated.

Use #get_all_scopes with filter by name

Get a scope by name

Parameters:

  • scope_name (String)

    name of the scope

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

Returns:

Raises:



238
239
240
241
# File 'lib/couchbase/management/collection_manager.rb', line 238

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

#update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT, options = Options::Collection::UpdateCollection::DEFAULT) ⇒ Object

Updates the settings of an existing collection

Parameters:

  • scope_name (String)

    the name of the scope the collection is in

  • collection_name (String)

    the name of the collection to be updated

  • settings (UpdateCollectionSettings) (defaults to: UpdateCollectionSettings::DEFAULT)

    the settings that should be updated

Raises:



316
317
318
319
# File 'lib/couchbase/management/collection_manager.rb', line 316

def update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT,
                      options = Options::Collection::UpdateCollection::DEFAULT)
  @backend.collection_update(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend)
end