-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.go
49 lines (42 loc) · 1.2 KB
/
index.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
// DynamoDB Table Index
package dynamodb
import (
SDK "github.com/aws/aws-sdk-go/service/dynamodb"
)
// projection type of the index.
// see: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Projection.html
const (
ProjectionTypeAll = "ALL"
ProjectionTypeKeysOnly = "KEYS_ONLY"
)
// NewLSI returns initilized LocalSecondaryIndex.
func NewLSI(name string, schema []*SDK.KeySchemaElement, projection ...string) *SDK.LocalSecondaryIndex {
var proj string
switch {
case len(projection) == 1:
proj = projection[0]
default:
proj = ProjectionTypeAll
}
return &SDK.LocalSecondaryIndex{
IndexName: &name,
KeySchema: schema,
Projection: &SDK.Projection{ProjectionType: &proj},
}
}
// NewGSI returns initilized GlobalSecondaryIndex.
func NewGSI(name string, schema []*SDK.KeySchemaElement, tp *SDK.ProvisionedThroughput, projection ...string) *SDK.GlobalSecondaryIndex {
var proj string
switch {
case len(projection) == 1:
proj = projection[0]
default:
proj = ProjectionTypeAll
}
return &SDK.GlobalSecondaryIndex{
IndexName: &name,
KeySchema: schema,
ProvisionedThroughput: tp,
Projection: &SDK.Projection{ProjectionType: &proj},
}
}