Class: Couchbase::Management::CollectionManager
- Inherits:
-
Object
- Object
- Couchbase::Management::CollectionManager
- 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
-
#create_collection(*args) ⇒ Object
Creates a new collection.
-
#create_scope(scope_name, options = Options::Collection::CreateScope.new) ⇒ Object
Creates a new scope.
-
#drop_collection(*args) ⇒ Object
Removes a collection.
-
#drop_scope(scope_name, options = Options::Collection::DropScope.new) ⇒ Object
Removes a scope.
-
#get_all_scopes(options = Options::Collection::GetAllScopes.new) ⇒ Array<ScopeSpec>
Get all scopes.
-
#get_scope(scope_name, options = GetScopeOptions.new) ⇒ ScopeSpec
deprecated
Deprecated.
Use #get_all_scopes with filter by name
-
#initialize(backend, bucket_name) ⇒ CollectionManager
constructor
A new instance of CollectionManager.
-
#update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT, options = Options::Collection::UpdateCollection::DEFAULT) ⇒ Object
Updates the settings of an existing collection.
Constructor Details
#initialize(backend, bucket_name) ⇒ CollectionManager
Returns a new instance of CollectionManager.
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
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] = 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, .to_backend) else scope_name = args[0] collection_name = args[1] settings = args[2] || CreateCollectionSettings::DEFAULT = args[3] || Options::Collection::CreateCollection::DEFAULT @backend.collection_create(@bucket_name, scope_name, collection_name, settings.to_backend, .to_backend) end end |
#create_scope(scope_name, options = Options::Collection::CreateScope.new) ⇒ Object
Creates a new scope
253 254 255 |
# File 'lib/couchbase/management/collection_manager.rb', line 253 def create_scope(scope_name, = Options::Collection::CreateScope.new) @backend.scope_create(@bucket_name, scope_name, .to_backend) end |
#drop_collection(scope_name, collection_name, settings = CreateCollectionSettings::DEFAULT) ⇒ Object #drop_collection(collection, options = Options::Collection::CreateCollection) ⇒ Object
Removes a collection
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] = 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, .to_backend) else scope_name = args[0] collection_name = args[1] = args[2] || Options::Collection::CreateCollection::DEFAULT @backend.collection_drop(@bucket_name, scope_name, collection_name, .to_backend) end end |
#drop_scope(scope_name, options = Options::Collection::DropScope.new) ⇒ Object
Removes a scope
265 266 267 |
# File 'lib/couchbase/management/collection_manager.rb', line 265 def drop_scope(scope_name, = Options::Collection::DropScope.new) @backend.scope_drop(@bucket_name, scope_name, .to_backend) end |
#get_all_scopes(options = Options::Collection::GetAllScopes.new) ⇒ Array<ScopeSpec>
Get all scopes
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::Collection::GetAllScopes.new) res = @backend.scope_get_all(@bucket_name, .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
Use #get_all_scopes with filter by name
Get a scope by name
238 239 240 241 |
# File 'lib/couchbase/management/collection_manager.rb', line 238 def get_scope(scope_name, = GetScopeOptions.new) get_all_scopes(Options::Collection::GetAllScopes(timeout: .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
316 317 318 319 |
# File 'lib/couchbase/management/collection_manager.rb', line 316 def update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT, = Options::Collection::UpdateCollection::DEFAULT) @backend.collection_update(@bucket_name, scope_name, collection_name, settings.to_backend, .to_backend) end |