-
Notifications
You must be signed in to change notification settings - Fork 14
/
example_test.go
56 lines (47 loc) · 1.2 KB
/
example_test.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
package dynago_test
import (
"fmt"
"github.com/underarmour/dynago"
)
var region, accessKey, secretKey, table string
func Example() {
client := dynago.NewAwsClient(region, accessKey, secretKey)
query := client.Query(table).
FilterExpression("NumViews > :views").
Param(":views", 50).
Desc()
result, err := query.Execute()
if err != nil {
// do something
}
for _, row := range result.Items {
fmt.Printf("Name: %s, Views: %d", row["Name"], row["NumViews"])
}
}
func Example_marshaling(client *dynago.Client) {
type MyStruct struct {
Id int64
Name string
Description string
Tags []string
Address struct {
City string
State string
}
}
var data MyStruct
doc := dynago.Document{
// Basic fields like numbers and strings get marshaled automatically
"Id": data.Id,
"Name": data.Name,
"Description": data.Description,
// StringSet is compatible with []string so we can simply cast it
"Tags": dynago.StringSet(data.Tags),
// We don't automatically marshal structs, nest it in a document
"Address": dynago.Document{
"City": data.Address.City,
"State": data.Address.State,
},
}
client.PutItem("Table", doc).Execute()
}