diff --git a/collection_crud.go b/collection_crud.go index f99c3a4c..83a24ef0 100644 --- a/collection_crud.go +++ b/collection_crud.go @@ -183,7 +183,7 @@ type ExistsOptions struct { } // Exists checks if a document exists for the given id. -func (c *Collection) Exists(id string, opts *ExistsOptions) (docOut *ExistsResult, errOut error) { +func (c *Collection) Exists(id string, opts *ExistsOptions) (docOut ExistsResult, errOut error) { if opts == nil { opts = &ExistsOptions{} } diff --git a/kvprovider.go b/kvprovider.go index b8cf002e..0a231649 100644 --- a/kvprovider.go +++ b/kvprovider.go @@ -11,7 +11,7 @@ type kvProvider interface { Remove(*Collection, string, *RemoveOptions) (*MutationResult, error) // Done Get(*Collection, string, *GetOptions) (*GetResult, error) // Done - Exists(*Collection, string, *ExistsOptions) (*ExistsResult, error) // Done + Exists(*Collection, string, *ExistsOptions) (ExistsResult, error) // Done GetAndTouch(*Collection, string, time.Duration, *GetAndTouchOptions) (*GetResult, error) // Done GetAndLock(*Collection, string, time.Duration, *GetAndLockOptions) (*GetResult, error) // Done Unlock(*Collection, string, Cas, *UnlockOptions) error // Done diff --git a/kvprovider_core.go b/kvprovider_core.go index 2e9e76f9..c229c1ce 100644 --- a/kvprovider_core.go +++ b/kvprovider_core.go @@ -552,7 +552,7 @@ func (p *kvProviderCore) GetAndLock(c *Collection, id string, lockTime time.Dura return getOut, errOut } -func (p *kvProviderCore) Exists(c *Collection, id string, opts *ExistsOptions) (*ExistsResult, error) { +func (p *kvProviderCore) Exists(c *Collection, id string, opts *ExistsOptions) (ExistsResult, error) { opm := newKvOpManagerCore(c, "exists", opts.ParentSpan, p) defer opm.Finish(false) @@ -566,7 +566,7 @@ func (p *kvProviderCore) Exists(c *Collection, id string, opts *ExistsOptions) ( return nil, err } - var docExists *ExistsResult + var docExists ExistsResult var errOut error err := opm.Wait(p.agent.GetMeta(gocbcore.GetMetaOptions{ Key: opm.DocumentID(), @@ -578,8 +578,8 @@ func (p *kvProviderCore) Exists(c *Collection, id string, opts *ExistsOptions) ( User: opm.Impersonate(), }, func(res *gocbcore.GetMetaResult, err error) { if errors.Is(err, ErrDocumentNotFound) { - docExists = &ExistsResult{ - Result: Result{ + docExists = &existsResult{ + result: Result{ cas: Cas(0), }, docExists: false, @@ -595,8 +595,8 @@ func (p *kvProviderCore) Exists(c *Collection, id string, opts *ExistsOptions) ( } if res != nil { - docExists = &ExistsResult{ - Result: Result{ + docExists = &existsResult{ + result: Result{ cas: Cas(res.Cas), }, docExists: res.Deleted == 0, diff --git a/kvprovider_ps.go b/kvprovider_ps.go index 198a3d7c..277dc222 100644 --- a/kvprovider_ps.go +++ b/kvprovider_ps.go @@ -603,7 +603,7 @@ func (p *kvProviderPs) GetAndLock(c *Collection, id string, lockTime time.Durati return &resOut, nil } -func (p *kvProviderPs) Exists(c *Collection, id string, opts *ExistsOptions) (*ExistsResult, error) { +func (p *kvProviderPs) Exists(c *Collection, id string, opts *ExistsOptions) (ExistsResult, error) { opm := newKvOpManagerPs(c, "exists", opts.ParentSpan) defer opm.Finish(false) @@ -630,8 +630,8 @@ func (p *kvProviderPs) Exists(c *Collection, id string, opts *ExistsOptions) (*E return nil, err } - resOut := ExistsResult{ - Result: Result{ + resOut := existsResult{ + result: Result{ Cas(res.Cas), }, docExists: res.Result, diff --git a/results.go b/results.go index b7c9f27b..5d739efd 100644 --- a/results.go +++ b/results.go @@ -328,16 +328,25 @@ func (r *LookupInReplicaResult) IsReplica() bool { } // ExistsResult is the return type of Exist operations. -type ExistsResult struct { - Result +type ExistsResult interface { + Exists() bool + Result() Result +} + +type existsResult struct { + result Result docExists bool } // Exists returns whether or not the document exists. -func (d *ExistsResult) Exists() bool { +func (d *existsResult) Exists() bool { return d.docExists } +func (d *existsResult) Result() Result { + return d.result +} + // MutationResult is the return type of any store related operations. It contains Cas and mutation tokens. type MutationResult struct { Result