public static Task DropScopeAsync(this ICouchbaseCollectionManager manager, string scopeName, Action <DropScopeOptions> configureOptions) { var options = new DropScopeOptions(); configureOptions(options); return(manager.DropScopeAsync(scopeName, options)); }
public async Task ExecuteAsync() { Console.WriteLine("scopeAdmin"); { // tag::scopeAdmin[] ICluster clusterAdmin = await Cluster.ConnectAsync( "couchbase://localhost", "Administrator", "password"); IUserManager users = clusterAdmin.Users; var user = new User("scopeAdmin") { Password = "******", DisplayName = "Manage Scopes [travel-sample:*]", Roles = new List <Role>() { new Role("scope_admin", "travel-sample"), new Role("data_reader", "travel-sample") } }; await users.UpsertUserAsync(user); // end::scopeAdmin[] } ICluster cluster = await Cluster.ConnectAsync("couchbase://localhost", "scopeAdmin", "password"); IBucket bucket = await cluster.BucketAsync("travel-sample"); // tag::create-collection-manager[] ICouchbaseCollectionManager collectionMgr = bucket.Collections; // end::create-collection-manager[] { Console.WriteLine("create-scope"); // tag::create-scope[] try { await collectionMgr.CreateScopeAsync("example-scope"); } catch (ScopeExistsException) { Console.WriteLine("The scope already exists"); } // end::create-scope[] } { Console.WriteLine("create-collection"); // tag::create-collection[] var spec = new CollectionSpec("example-scope", "example-collection"); try { await collectionMgr.CreateCollectionAsync(spec); } catch (CollectionExistsException) { Console.WriteLine("Collection already exists"); } catch (ScopeNotFoundException) { Console.WriteLine("The specified parent scope doesn't exist"); } // end::create-collection[] Console.WriteLine("listing-scope-collection"); // tag::listing-scope-collection[] var scopes = await collectionMgr.GetAllScopesAsync(); foreach (ScopeSpec scopeSpec in scopes) { Console.WriteLine($"Scope: {scopeSpec.Name}"); foreach (CollectionSpec collectionSpec in scopeSpec.Collections) { Console.WriteLine($" - {collectionSpec.Name}"); } } // end::listing-scope-collection[] Console.WriteLine("drop-collection"); // tag::drop-collection[] try { await collectionMgr.DropCollectionAsync(spec); } catch (CollectionNotFoundException) { Console.WriteLine("The specified collection doesn't exist"); } catch (ScopeNotFoundException) { Console.WriteLine("The specified parent scope doesn't exist"); } // end::drop-collection[] } { Console.WriteLine("drop-scope"); // tag::drop-scope[] try { await collectionMgr.DropScopeAsync("example-scope"); } catch (ScopeNotFoundException) { Console.WriteLine("The specified scope doesn't exist"); } // end::drop-scope[] } }
public static Task DropScopeAsync(this ICouchbaseCollectionManager manager, string scopeName) { return(manager.DropScopeAsync(scopeName, DropScopeOptions.Default)); }
public static IAsyncDisposable DropScopeOnDispose(ICouchbaseCollectionManager collectionManager, string scopeName, ITestOutputHelper?outputHelper = null) { return(new DisposeCleanerAsync(() => collectionManager.DropScopeAsync(scopeName), outputHelper)); }