forked from dugancathal/dynago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest_put_item.go
95 lines (79 loc) · 2.47 KB
/
request_put_item.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package dynago
type putItemRequest struct {
TableName string
Item Document
ConditionExpression string `json:",omitempty"`
expressionAttributes
// TODO ReturnItemCollectionMetrics
ReturnConsumedCapacity CapacityDetail `json:",omitempty"`
ReturnValues ReturnValues `json:",omitempty"`
}
func newPutItem(client *Client, table string, item Document) *PutItem {
return &PutItem{
client: client,
req: putItemRequest{
TableName: table,
Item: item,
},
}
}
// PutItem is used to create/replace single items in the table.
type PutItem struct {
client *Client
req putItemRequest
}
// ConditionExpression sets a condition which if not satisfied, the PutItem is not performed.
func (p PutItem) ConditionExpression(expression string, params ...Params) *PutItem {
p.req.ConditionExpression = expression
p.req.paramsHelper(params)
return &p
}
/*
Item lets you change the item after construction.
Note this replaces the whole item, it doesn't merge with the existing data.
*/
func (p PutItem) Item(item Document) *PutItem {
p.req.Item = item
return &p
}
// Param is a shortcut to set a single bound parameter.
func (p PutItem) Param(key string, value interface{}) *PutItem {
p.req.paramHelper(key, value)
return &p
}
// Params sets multiple bound parameters on this query.
func (p PutItem) Params(params ...Params) *PutItem {
p.req.paramsHelper(params)
return &p
}
// ReturnConsumedCapacity enables capacity reporting on this PutItem.
func (p PutItem) ReturnConsumedCapacity(consumedCapacity CapacityDetail) *PutItem {
p.req.ReturnConsumedCapacity = consumedCapacity
return &p
}
// ReturnValues can allow you to ask for either previous or new values on an update
func (p PutItem) ReturnValues(returnValues ReturnValues) *PutItem {
p.req.ReturnValues = returnValues
return &p
}
/*
Execute this PutItem.
PutItemResult will be nil unless ReturnValues or ReturnConsumedCapacity is set.
*/
func (p *PutItem) Execute() (res *PutItemResult, err error) {
return p.client.executor.PutItem(p)
}
// PutItem on this executor.
func (e *AwsExecutor) PutItem(p *PutItem) (res *PutItemResult, err error) {
if (p.req.ReturnValues != ReturnNone && p.req.ReturnValues != "") || p.req.ReturnConsumedCapacity != "" {
err = e.MakeRequestUnmarshal("PutItem", &p.req, &res)
} else {
_, err = e.makeRequest("PutItem", &p.req)
}
return
}
// PutItemResult is returned when a PutItem is executed.
type PutItemResult struct {
Attributes Document
ConsumedCapacity *ConsumedCapacity
}