Class: Couchbase::Management::CollectionManager
- Inherits:
-
Object
- Object
- Couchbase::Management::CollectionManager
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/couchbase/management/collection_manager.rb,
/Users/sergey.auseyau/code/couchbase-ruby-client/lib/couchbase/management/collection_manager.rb more...
Defined Under Namespace
Classes: GetScopeOptions
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.
199 200 201 202 |
# File 'lib/couchbase/management/collection_manager.rb', line 199 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
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/couchbase/management/collection_manager.rb', line 286 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
251 252 253 |
# File 'lib/couchbase/management/collection_manager.rb', line 251 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
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/couchbase/management/collection_manager.rb', line 336 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
263 264 265 |
# File 'lib/couchbase/management/collection_manager.rb', line 263 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
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/couchbase/management/collection_manager.rb', line 209 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
Deprecated.
Use #get_all_scopes with filter by name
Get a scope by name
236 237 238 239 |
# File 'lib/couchbase/management/collection_manager.rb', line 236 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
314 315 316 317 |
# File 'lib/couchbase/management/collection_manager.rb', line 314 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 |