Skip to content

Commit f0565f4

Browse files
authored
chore: transact items to be a variadic function,type alias for TransactWriteItem type (#6)
- [x] transact items to be a variadic function - [x] add type alias for TransactWriteItem type
2 parents 4a32342 + 51556e2 commit f0565f4

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/aws/aws-sdk-go-v2/config"
99
"github.com/aws/aws-sdk-go-v2/credentials"
1010
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
11+
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
1112
)
1213

1314
type ClientOptions struct {
@@ -25,6 +26,8 @@ type Client struct {
2526
Keys map[string]string
2627
}
2728

29+
type TransactWriteItem types.TransactWriteItem
30+
2831
// Create a new instance of DynamoTable. internally creates aws connection configuration for the db
2932
// If DynamoTable.Endpoint is specified connects to the db at the given URL, or the default credential of the system is used
3033
// To connect to AWS DynamoDB from a running pod or EC2 instance, use the default credentials without Endpoint option

tests/transact_items_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestTransactItems(t *testing.T) {
9999
}
100100
//perform operations
101101
if len(tc.operations) > 0 {
102-
err := table.TransactItems(ctx, tc.operations)
102+
err := table.TransactItems(ctx, tc.operations...)
103103
if err != nil {
104104
t.Fatalf("error occurred %s", err)
105105
}

transaction_items.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (t *Client) WithPutItem(pk string, sk string, item interface{}) types.Trans
4646

4747
// TransactItems is a synchronous for writing or deletion operation performed in dynamodb grouped together
4848

49-
func (t *Client) TransactItems(ctx context.Context, input []types.TransactWriteItem) error {
49+
func (t *Client) TransactItems(ctx context.Context, input ...types.TransactWriteItem) error {
5050
_, err := t.client.TransactWriteItems(ctx, &dynamodb.TransactWriteItemsInput{
5151
TransactItems: input,
5252
})

0 commit comments

Comments
 (0)