-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.go
53 lines (42 loc) · 1.63 KB
/
interface.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
package dynago
import (
"context"
"strconv"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)
type Attribute = types.AttributeValue
func StringValue(v string) *types.AttributeValueMemberS {
return &types.AttributeValueMemberS{Value: v}
}
func NumberValue(v int64) *types.AttributeValueMemberN {
return &types.AttributeValueMemberN{Value: strconv.FormatInt(v, 10)}
}
func BoolValue(v bool) *types.AttributeValueMemberBOOL {
return &types.AttributeValueMemberBOOL{Value: v}
}
type WriteAPI interface {
// Create or update given item in DynamoDB. Must implemenmt DynamoRecord interface.
// DynamoRecord.GetKeys will be called to get values for parition and sort keys.
PutItem(ctx context.Context, pk Attribute, sk Attribute, item interface{}) error
DeleteItem(ctx context.Context, pk string, sk string) error
}
type TransactionAPI interface {
TransactPutItems(ctx context.Context, items []*TransactPutItemsInput) error
TransactItems(ctx context.Context, input ...types.TransactWriteItem) error
}
type ReadAPI interface {
GetItem(ctx context.Context, pk Attribute, sk Attribute, out interface{}) (error, bool)
BatchGetItems(ctx context.Context, input []AttributeRecord, out interface{}) error
}
type QueryAPI interface {
// Perform a DynamoDB query with the key condition expression in first argument.
//
// If key condition contains template params eg: pk = :pk for values, second argument should provide values
Query(ctx context.Context, condition string, params map[string]Attribute, out interface{}, opts ...QueryOptions) (map[string]Attribute, error)
}
type DynamoClient interface {
ReadAPI
WriteAPI
QueryAPI
TransactionAPI
}