Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collection_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
2 changes: 1 addition & 1 deletion kvprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions kvprovider_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions kvprovider_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand Down
15 changes: 12 additions & 3 deletions results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down