Skip to content

Commit

Permalink
chore: transact items to be a variadic function,type alias for Transa…
Browse files Browse the repository at this point in the history
…ctWriteItem type (#6)

- [x] transact items to be a variadic function
- [x] add type alias for TransactWriteItem type
  • Loading branch information
omkar-till authored Nov 22, 2023
2 parents bbd199d + 51556e2 commit 5a8ccd2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
)

type ClientOptions struct {
Expand All @@ -25,6 +26,8 @@ type Client struct {
Keys map[string]string
}

type TransactWriteItem types.TransactWriteItem

// Create a new instance of DynamoTable. internally creates aws connection configuration for the db
// If DynamoTable.Endpoint is specified connects to the db at the given URL, or the default credential of the system is used
// To connect to AWS DynamoDB from a running pod or EC2 instance, use the default credentials without Endpoint option
Expand Down
2 changes: 1 addition & 1 deletion tests/transact_items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestTransactItems(t *testing.T) {
}
//perform operations
if len(tc.operations) > 0 {
err := table.TransactItems(ctx, tc.operations)
err := table.TransactItems(ctx, tc.operations...)
if err != nil {
t.Fatalf("error occurred %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion transaction_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (t *Client) WithPutItem(pk string, sk string, item interface{}) types.Trans

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

func (t *Client) TransactItems(ctx context.Context, input []types.TransactWriteItem) error {
func (t *Client) TransactItems(ctx context.Context, input ...types.TransactWriteItem) error {
_, err := t.client.TransactWriteItems(ctx, &dynamodb.TransactWriteItemsInput{
TransactItems: input,
})
Expand Down

0 comments on commit 5a8ccd2

Please sign in to comment.