-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdelete.go
71 lines (57 loc) · 1.44 KB
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package goriak
import (
"errors"
riak "github.com/basho/riak-go-client"
)
type DeleteCommand struct {
c *Command
builder *riak.DeleteValueCommandBuilder
}
// Delete deletes the value stored as key
func (c *Command) Delete(key string) *DeleteCommand {
builder := riak.NewDeleteValueCommandBuilder().
WithBucket(c.bucket).
WithBucketType(c.bucketType).
WithKey(key)
return &DeleteCommand{
c: c,
builder: builder,
}
}
func (c *DeleteCommand) WithDw(dw uint32) *DeleteCommand {
c.builder.WithDw(dw)
return c
}
// WithPw sets the number of primary nodes that must report back a successful write for the command to be successful.
func (c *DeleteCommand) WithPw(pw uint32) *DeleteCommand {
c.builder.WithPw(pw)
return c
}
func (c *DeleteCommand) WithPr(pr uint32) *DeleteCommand {
c.builder.WithPr(pr)
return c
}
func (c *DeleteCommand) WithR(r uint32) *DeleteCommand {
c.builder.WithR(r)
return c
}
// WithW sets the number of nodes that must report back a successful write for the command to be successful.
func (c *DeleteCommand) WithW(w uint32) *DeleteCommand {
c.builder.WithW(w)
return c
}
func (c *DeleteCommand) Run(session *Session) (*Result, error) {
cmd, err := c.builder.Build()
if err != nil {
return nil, err
}
err = session.riak.Execute(cmd)
if err != nil {
return nil, err
}
res := cmd.(*riak.DeleteValueCommand)
if !res.Success() {
return nil, errors.New("not successful")
}
return &Result{}, nil
}