|
1
|
|
|
package dynamodb |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
|
|
6
|
|
|
SDK "github.com/aws/aws-sdk-go-v2/service/dynamodb" |
|
7
|
|
|
|
|
8
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
|
9
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers" |
|
10
|
|
|
) |
|
11
|
|
|
|
|
12
|
|
|
// CreateTable executes `CreateTable` operation. |
|
13
|
|
|
func (svc *DynamoDB) CreateTable(ctx context.Context, r CreateTableRequest) (*CreateTableResult, error) { |
|
14
|
|
|
out, err := svc.RawCreateTable(ctx, r.ToInput()) |
|
15
|
|
|
if err == nil { |
|
16
|
|
|
return NewCreateTableResult(out), nil |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
err = svc.errWrap(errors.ErrorData{ |
|
20
|
|
|
Err: err, |
|
21
|
|
|
AWSOperation: "CreateTable", |
|
22
|
|
|
}) |
|
23
|
|
|
svc.Errorf(err.Error()) |
|
|
|
|
|
|
24
|
|
|
return nil, err |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
// CreateTableRequest has parameters for `CreateTable` operation. |
|
28
|
|
|
type CreateTableRequest struct { |
|
29
|
|
|
TableName string |
|
30
|
|
|
AttributeDefinitions []AttributeDefinition |
|
31
|
|
|
KeySchema []KeySchemaElement |
|
32
|
|
|
|
|
33
|
|
|
// optional |
|
34
|
|
|
BillingMode BillingMode |
|
35
|
|
|
GlobalSecondaryIndexes []GlobalSecondaryIndex |
|
36
|
|
|
LocalSecondaryIndexes []LocalSecondaryIndex |
|
37
|
|
|
ProvisionedThroughput ProvisionedThroughput |
|
38
|
|
|
SSESpecification SSESpecification |
|
39
|
|
|
StreamSpecification StreamSpecification |
|
40
|
|
|
Tags []Tag |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
func (r CreateTableRequest) ToInput() *SDK.CreateTableInput { |
|
|
|
|
|
|
44
|
|
|
in := &SDK.CreateTableInput{} |
|
45
|
|
|
|
|
46
|
|
|
if r.TableName != "" { |
|
47
|
|
|
in.TableName = pointers.String(r.TableName) |
|
48
|
|
|
} |
|
49
|
|
|
if len(r.AttributeDefinitions) != 0 { |
|
50
|
|
|
list := make([]SDK.AttributeDefinition, len(r.AttributeDefinitions)) |
|
51
|
|
|
for i, v := range r.AttributeDefinitions { |
|
52
|
|
|
list[i] = v.ToSDK() |
|
53
|
|
|
} |
|
54
|
|
|
in.AttributeDefinitions = list |
|
55
|
|
|
} |
|
56
|
|
|
if len(r.KeySchema) != 0 { |
|
57
|
|
|
list := make([]SDK.KeySchemaElement, len(r.KeySchema)) |
|
58
|
|
|
for i, v := range r.KeySchema { |
|
59
|
|
|
list[i] = v.ToSDK() |
|
60
|
|
|
} |
|
61
|
|
|
in.KeySchema = list |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
in.BillingMode = SDK.BillingMode(r.BillingMode) |
|
65
|
|
|
|
|
66
|
|
|
if len(r.GlobalSecondaryIndexes) != 0 { |
|
67
|
|
|
list := make([]SDK.GlobalSecondaryIndex, len(r.GlobalSecondaryIndexes)) |
|
68
|
|
|
for i, v := range r.GlobalSecondaryIndexes { |
|
69
|
|
|
list[i] = v.ToSDK() |
|
70
|
|
|
} |
|
71
|
|
|
in.GlobalSecondaryIndexes = list |
|
72
|
|
|
} |
|
73
|
|
|
if len(r.LocalSecondaryIndexes) != 0 { |
|
74
|
|
|
list := make([]SDK.LocalSecondaryIndex, len(r.LocalSecondaryIndexes)) |
|
75
|
|
|
for i, v := range r.LocalSecondaryIndexes { |
|
76
|
|
|
list[i] = v.ToSDK() |
|
77
|
|
|
} |
|
78
|
|
|
in.LocalSecondaryIndexes = list |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if r.ProvisionedThroughput.hasValue() { |
|
82
|
|
|
v := r.ProvisionedThroughput.ToSDK() |
|
83
|
|
|
in.ProvisionedThroughput = &v |
|
84
|
|
|
} |
|
85
|
|
|
if r.SSESpecification.hasValue() { |
|
86
|
|
|
v := r.SSESpecification.ToSDK() |
|
87
|
|
|
in.SSESpecification = &v |
|
88
|
|
|
} |
|
89
|
|
|
if r.StreamSpecification.hasValue() { |
|
90
|
|
|
v := r.StreamSpecification.ToSDK() |
|
91
|
|
|
in.StreamSpecification = &v |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if len(r.Tags) != 0 { |
|
95
|
|
|
list := make([]SDK.Tag, len(r.Tags)) |
|
96
|
|
|
for i, v := range r.Tags { |
|
97
|
|
|
list[i] = v.ToSDK() |
|
98
|
|
|
} |
|
99
|
|
|
in.Tags = list |
|
100
|
|
|
} |
|
101
|
|
|
return in |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
// CreateTableResult contains results from `CreateTable` operation. |
|
105
|
|
|
type CreateTableResult struct { |
|
106
|
|
|
TableDescription TableDescription |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
func NewCreateTableResult(output *SDK.CreateTableResponse) *CreateTableResult { |
|
|
|
|
|
|
110
|
|
|
r := &CreateTableResult{} |
|
111
|
|
|
if output == nil { |
|
112
|
|
|
return r |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
if output.TableDescription != nil { |
|
116
|
|
|
r.TableDescription = newTableDescription(*output.TableDescription) |
|
117
|
|
|
} |
|
118
|
|
|
return r |
|
119
|
|
|
} |
|
120
|
|
|
|