Class: Couchbase::Management::CollectionManager

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/couchbase/management/collection_manager.rb

Defined Under Namespace

Classes: GetScopeOptions

Constant Summary collapse

GetAllScopesOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TODO: deprecate after 3.2

::Couchbase::Management::Options::Collection::GetAllScopes
CreateScopeOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TODO: deprecate after 3.2

::Couchbase::Management::Options::Collection::CreateScope
DropScopeOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TODO: deprecate after 3.2

::Couchbase::Management::Options::Collection::DropScope
CreateCollectionOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TODO: deprecate after 3.2

::Couchbase::Management::Options::Collection::CreateCollection
DropCollectionOptions =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

TODO: deprecate after 3.2

::Couchbase::Management::Options::Collection::DropCollection

Instance Method Summary collapse

Constructor Details

#initialize(backend, bucket_name, observability) ⇒ CollectionManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CollectionManager.

Parameters:



204
205
206
207
208
# File 'lib/couchbase/management/collection_manager.rb', line 204

def initialize(backend, bucket_name, observability)
  @backend = backend
  @bucket_name = bucket_name
  @observability = observability
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:



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/couchbase/management/collection_manager.rb', line 306

def create_collection(*args)
  scope_name, collection_name, settings, options =
    if args[0].is_a?(CollectionSpec)
      warn "Calling create_collection with a CollectionSpec object has been deprecated, supply scope name, " \
           "collection name and optionally a CreateCollectionSettings instance"
      collection = args[0]
      [
        collection.scope_name,
        collection.name,
        CreateCollectionSettings.new(max_expiry: collection.max_expiry, history: collection.history),
        args[1] || Options::Collection::CreateCollection::DEFAULT,
      ]
    else
      [
        args[0],
        args[1],
        args[2] || CreateCollectionSettings::DEFAULT,
        args[3] || Options::Collection::CreateCollection::DEFAULT,
      ]
    end

  @observability.record_operation(Observability::OP_CM_CREATE_COLLECTION, options.parent_span, self, :management) do |obs_handler|
    obs_handler.add_scope_name(scope_name)
    obs_handler.add_collection_name(collection_name)

    @backend.collection_create(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend, obs_handler)
  end
end

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

Creates a new scope

Parameters:

Returns:

  • void

Raises:

  • (ArgumentError)


263
264
265
266
267
268
269
# File 'lib/couchbase/management/collection_manager.rb', line 263

def create_scope(scope_name, options = Options::Collection::CreateScope.new)
  @observability.record_operation(Observability::OP_CM_CREATE_SCOPE, options.parent_span, self, :management) do |obs_handler|
    obs_handler.add_scope_name(scope_name)

    @backend.scope_create(@bucket_name, scope_name, options.to_backend, obs_handler)
  end
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:



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/couchbase/management/collection_manager.rb', line 371

def drop_collection(*args)
  scope_name, collection_name, options =
    if args[0].is_a?(CollectionSpec)
      warn "Calling drop_collection with a CollectionSpec object has been deprecated, supply scope name and collection name"
      collection = args[0]
      [
        collection.scope_name,
        collection.name,
        args[1] || Options::Collection::CreateCollection::DEFAULT,
      ]
    else
      [
        args[0],
        args[1],
        args[2] || Options::Collection::CreateCollection::DEFAULT,
      ]
    end

  @observability.record_operation(Observability::OP_CM_DROP_COLLECTION, options.parent_span, self, :management) do |obs_handler|
    obs_handler.add_scope_name(scope_name)
    obs_handler.add_collection_name(collection_name)

    @backend.collection_drop(@bucket_name, scope_name, collection_name, options.to_backend, obs_handler)
  end
end

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

Removes a scope

Parameters:

Returns:

  • void

Raises:



279
280
281
282
283
284
285
# File 'lib/couchbase/management/collection_manager.rb', line 279

def drop_scope(scope_name, options = Options::Collection::DropScope.new)
  @observability.record_operation(Observability::OP_CM_DROP_SCOPE, options.parent_span, self, :management) do |obs_handler|
    obs_handler.add_scope_name(scope_name)

    @backend.scope_drop(@bucket_name, scope_name, options.to_backend, obs_handler)
  end
end

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

Get all scopes

Parameters:

Returns:



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/couchbase/management/collection_manager.rb', line 215

def get_all_scopes(options = Options::Collection::GetAllScopes.new)
  @observability.record_operation(Observability::OP_CM_GET_ALL_SCOPES, options.parent_span, self, :management) do |obs_handler|
    res = @backend.scope_get_all(@bucket_name, options.to_backend, obs_handler)
    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
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:



244
245
246
247
248
249
250
251
# File 'lib/couchbase/management/collection_manager.rb', line 244

def get_scope(scope_name, options = GetScopeOptions.new)
  @observability.record_operation(Observability::OP_CM_GET_SCOPE, options.parent_span, self, :management) do |obs_handler|
    obs_handler.add_scope_name(scope_name)

    get_all_scopes(Options::Collection::GetAllScopes(timeout: options.timeout, parent_span: obs_handler.op_span))
      .find { |scope| scope.name == scope_name } or raise Error::ScopeNotFound, "unable to find scope #{scope_name}"
  end
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:



344
345
346
347
348
349
350
351
352
# File 'lib/couchbase/management/collection_manager.rb', line 344

def update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT,
                      options = Options::Collection::UpdateCollection::DEFAULT)
  @observability.record_operation(Observability::OP_CM_UPDATE_COLLECTION, options.parent_span, self, :management) do |obs_handler|
    obs_handler.add_scope_name(scope_name)
    obs_handler.add_collection_name(collection_name)

    @backend.collection_update(@bucket_name, scope_name, collection_name, settings.to_backend, options.to_backend, obs_handler)
  end
end