Class: Couchbase::Management::CollectionManager
- Inherits:
-
Object
- Object
- Couchbase::Management::CollectionManager
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/couchbase/management/collection_manager.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/lib/couchbase/management/collection_manager.rb
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
-
#update_collection(scope_name, collection_name, settings = UpdateCollectionSettings::DEFAULT, options = Options::Collection::UpdateCollection::DEFAULT) ⇒ Object
Updates the settings of an existing collection.
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
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, = 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, .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, .to_backend, obs_handler) end end |
#create_scope(scope_name, options = Options::Collection::CreateScope.new) ⇒ Object
Creates a new scope
263 264 265 266 267 268 269 |
# File 'lib/couchbase/management/collection_manager.rb', line 263 def create_scope(scope_name, = Options::Collection::CreateScope.new) @observability.record_operation(Observability::OP_CM_CREATE_SCOPE, .parent_span, self, :management) do |obs_handler| obs_handler.add_scope_name(scope_name) @backend.scope_create(@bucket_name, scope_name, .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
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, = 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, .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, .to_backend, obs_handler) end end |
#drop_scope(scope_name, options = Options::Collection::DropScope.new) ⇒ Object
Removes a scope
279 280 281 282 283 284 285 |
# File 'lib/couchbase/management/collection_manager.rb', line 279 def drop_scope(scope_name, = Options::Collection::DropScope.new) @observability.record_operation(Observability::OP_CM_DROP_SCOPE, .parent_span, self, :management) do |obs_handler| obs_handler.add_scope_name(scope_name) @backend.scope_drop(@bucket_name, scope_name, .to_backend, obs_handler) end end |
#get_all_scopes(options = Options::Collection::GetAllScopes.new) ⇒ Array<ScopeSpec>
Get all scopes
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::Collection::GetAllScopes.new) @observability.record_operation(Observability::OP_CM_GET_ALL_SCOPES, .parent_span, self, :management) do |obs_handler| res = @backend.scope_get_all(@bucket_name, .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
244 245 246 247 248 249 250 251 |
# File 'lib/couchbase/management/collection_manager.rb', line 244 def get_scope(scope_name, = GetScopeOptions.new) @observability.record_operation(Observability::OP_CM_GET_SCOPE, .parent_span, self, :management) do |obs_handler| obs_handler.add_scope_name(scope_name) get_all_scopes(Options::Collection::GetAllScopes(timeout: .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
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::Collection::UpdateCollection::DEFAULT) @observability.record_operation(Observability::OP_CM_UPDATE_COLLECTION, .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, .to_backend, obs_handler) end end |