MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / CreateDataStore

Method CreateDataStore

base/collection.go:684–705  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
684func (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.
708func (b *GocbV2Bucket) DefaultDataStore() sgbucket.DataStore {

Calls 10

GetNameMethod · 0.95
MDFunction · 0.85
WaitForNoErrorFunction · 0.85
ErrorfMethod · 0.80
CreateScopeMethod · 0.80
CreateCollectionMethod · 0.80
ScopeNameMethod · 0.45
CollectionNameMethod · 0.45
CollectionMethod · 0.45
ExistsMethod · 0.45