CreateDataStore adds a collection from the bucket, and creates a scope if it does not exist. This code is synchronous and waits for the collection to be created.
(ctx context.Context, name sgbucket.DataStoreName)
| 682 | |
| 683 | // CreateDataStore adds a collection from the bucket, and creates a scope if it does not exist. This code is synchronous and waits for the collection to be created. |
| 684 | func (b *GocbV2Bucket) CreateDataStore(ctx context.Context, name sgbucket.DataStoreName) error { |
| 685 | if b.cluster == nil { |
| 686 | return fmt.Errorf("bucket %s has been closed", MD(b.GetName())) |
| 687 | } |
| 688 | // create scope first (if it doesn't already exist) |
| 689 | if name.ScopeName() != DefaultScope { |
| 690 | err := b.bucket.Collections().CreateScope(name.ScopeName(), nil) |
| 691 | if err != nil && !errors.Is(err, gocb.ErrScopeExists) { |
| 692 | return err |
| 693 | } |
| 694 | } |
| 695 | err := b.bucket.Collections().CreateCollection(gocb.CollectionSpec{Name: name.CollectionName(), ScopeName: name.ScopeName()}, nil) |
| 696 | if err != nil { |
| 697 | return err |
| 698 | } |
| 699 | // Can't use Collection.Exists since we can't get a collection until the collection exists on CBS |
| 700 | gocbCollection := b.bucket.Scope(name.ScopeName()).Collection(name.CollectionName()) |
| 701 | return WaitForNoError(ctx, func() error { |
| 702 | _, err := gocbCollection.Exists("fakedocid", nil) |
| 703 | return err |
| 704 | }) |
| 705 | } |
| 706 | |
| 707 | // DefaultDataStore returns the default collection for the bucket. |
| 708 | func (b *GocbV2Bucket) DefaultDataStore() sgbucket.DataStore { |