Skip to content

Commit

Permalink
feat: expiry and preserveExpiry added
Browse files Browse the repository at this point in the history
  • Loading branch information
erayarslan committed Jul 5, 2024
1 parent 8b9d948 commit 31ff188
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
24 changes: 20 additions & 4 deletions couchbase/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Client interface {
value []byte,
flags memd.SubdocDocFlag,
cas *gocbcore.Cas,
expiry uint32,
preserveExpiry bool,
cb gocbcore.MutateInCallback,
) error
CreateDocument(ctx context.Context,
Expand All @@ -46,6 +48,8 @@ type Client interface {
id []byte,
path []byte,
cas *gocbcore.Cas,
expiry uint32,
preserveExpiry bool,
cb gocbcore.MutateInCallback,
) error
Execute(ctx context.Context, action *CBActionDocument, callback func(err error))
Expand Down Expand Up @@ -86,6 +90,8 @@ func (s *client) CreatePath(ctx context.Context,
value []byte,
flags memd.SubdocDocFlag,
cas *gocbcore.Cas,
expiry uint32,
preserveExpiry bool,
cb gocbcore.MutateInCallback,
) error {
deadline, _ := ctx.Deadline()
Expand All @@ -100,6 +106,8 @@ func (s *client) CreatePath(ctx context.Context,
Path: string(path),
},
},
Expiry: expiry,
PreserveExpiry: preserveExpiry,
Deadline: deadline,
ScopeName: scopeName,
CollectionName: collectionName,
Expand Down Expand Up @@ -169,6 +177,8 @@ func (s *client) DeletePath(ctx context.Context,
id []byte,
path []byte,
cas *gocbcore.Cas,
expiry uint32,
preserveExpiry bool,
cb gocbcore.MutateInCallback,
) error {
deadline, _ := ctx.Deadline()
Expand All @@ -181,6 +191,8 @@ func (s *client) DeletePath(ctx context.Context,
Path: string(path),
},
},
Expiry: expiry,
PreserveExpiry: preserveExpiry,
Deadline: deadline,
ScopeName: scopeName,
CollectionName: collectionName,
Expand All @@ -201,7 +213,8 @@ func (s *client) Execute(ctx context.Context, action *CBActionDocument, callback

switch {
case action.Type == Set:
err = s.CreateDocument(ctx, s.config.ScopeName, s.config.CollectionName, action.ID, action.Source, 0, 0,
err = s.CreateDocument(ctx, s.config.ScopeName, s.config.CollectionName,
action.ID, action.Source, 0, action.Expiry,
func(result *gocbcore.StoreResult, err error) {
callback(err)
})
Expand All @@ -211,17 +224,20 @@ func (s *client) Execute(ctx context.Context, action *CBActionDocument, callback
flags = memd.SubdocDocFlagNone
}

err = s.CreatePath(ctx, s.config.ScopeName, s.config.CollectionName, action.ID, action.Path, action.Source, flags, casPtr,
err = s.CreatePath(ctx, s.config.ScopeName, s.config.CollectionName,
action.ID, action.Path, action.Source, flags, casPtr, action.Expiry, action.PreserveExpiry,
func(result *gocbcore.MutateInResult, err error) {
callback(err)
})
case action.Type == DeletePath:
err = s.DeletePath(ctx, s.config.ScopeName, s.config.CollectionName, action.ID, action.Path, casPtr,
err = s.DeletePath(ctx, s.config.ScopeName, s.config.CollectionName,
action.ID, action.Path, casPtr, action.Expiry, action.PreserveExpiry,
func(result *gocbcore.MutateInResult, err error) {
callback(err)
})
case action.Type == Delete:
err = s.DeleteDocument(ctx, s.config.ScopeName, s.config.CollectionName, action.ID, casPtr,
err = s.DeleteDocument(ctx, s.config.ScopeName, s.config.CollectionName,
action.ID, casPtr,
func(result *gocbcore.DeleteResult, err error) {
callback(err)
})
Expand Down
10 changes: 10 additions & 0 deletions couchbase/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@ type CBActionDocument struct {
ID []byte
Path []byte
Size int
Expiry uint32
PreserveExpiry bool
DisableAutoCreate bool
}

func (doc *CBActionDocument) SetCas(cas uint64) {
doc.Cas = &cas
}

func (doc *CBActionDocument) SetExpiry(expiry uint32) {
doc.Expiry = expiry
}

func (doc *CBActionDocument) SetPreserveExpiry(preserveExpiry bool) {
doc.PreserveExpiry = preserveExpiry
}

func (doc *CBActionDocument) SetDisableAutoCreate(value bool) {
doc.DisableAutoCreate = value
}
Expand Down

0 comments on commit 31ff188

Please sign in to comment.