• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..06-May-2021-

README.mdH A D06-May-20211.3 KiB4838

scanItems.goH A D06-May-20212.3 KiB9969

README.md

1# Example
2
3`scanItems` is an example how to use Amazon DynamoDB's Scan API operation with the SDK's `dynamodbattributes.UnmarshalListOfMaps` to unmarshal the Scan response's `Items` `[]map[string]*dynamodb.AttributeValue` field. This unmarshaler can be used with all `[]map[string]*dynamodb.AttributeValue` type fields.
4
5## Go Type
6
7The `Item` time will be used by the example to unmarshal the DynamoDB table's items to.
8
9```go
10type Item struct {
11	Key  int
12	Desc string
13	Data map[string]interface{}
14}
15```
16Use Go tags to define what the name is of the attribute in your DynamoDB table. See [AWS SDK for Go API Reference: Marshal](https://docs.aws.amazon.com/sdk-for-go/api/service/dynamodb/dynamodbattribute/#Marshal) for more information.
17
18In DynamoDB the structure of the item to be returned will be:
19```json
20{
21  "Data": {
22    "Value 1": "abc",
23    "Value 2": 1234567890
24  },
25  "Desc": "First ddb item",
26  "Key": 1
27}
28```
29
30## Usage
31
32`go run -tags example scanItems.go -table "<table_name>" -region "<optional_region>"`
33
34## Output
35
36```
370: Key: 123, Desc: An item in the DynamoDB table
38	Num Data Values: 0
391: Key: 2, Desc: Second ddb item
40	Num Data Values: 2
41	- "A Field": 123
42	- "Another Field": abc
432: Key: 1, Desc: First ddb item
44	Num Data Values: 2
45	- "Value 1": abc
46	- "Value 2": 1234567890
47```
48