Skip to content

Commit

Permalink
fix(fields): changed fields input to map[string]string to simplify
Browse files Browse the repository at this point in the history
The aim here is to not leak AWS SDK types were possible.
  • Loading branch information
wolfeidau committed Aug 7, 2021
1 parent 075128b commit aa7c3ab
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dynastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ func testAtomicPutIndex(t *testing.T, dSession Session) {
timeStamp := "20200103T1100Z"

// Put the key
err := kv.Put(key, WriteWithBytes(value), WriteWithFields(map[string]*dynamodb.AttributeValue{
"created": {S: aws.String(timeStamp)},
err := kv.Put(key, WriteWithBytes(value), WriteWithFields(map[string]string{
"created": timeStamp,
}))
assert.NoError(err)

Expand Down
9 changes: 4 additions & 5 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
"github.com/wolfeidau/dynastore"
)

Expand All @@ -25,9 +23,10 @@ type Index struct {
Created string `json:"created"`
}

func (cf *Index) ToFields() map[string]*dynamodb.AttributeValue {
attr, _ := dynamodbattribute.MarshalMap(cf)
return attr
func (cf *Index) ToFields() map[string]string {
return map[string]string{
"created": cf.Created,
}
}

func ExamplePartition_AtomicPut() {
Expand Down
10 changes: 8 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ func WriteWithString(val string) WriteOption {
}

// WriteWithFields assign fields to the top level record, this is used to assign attributes used in indexes
func WriteWithFields(fields map[string]*dynamodb.AttributeValue) WriteOption {
func WriteWithFields(fields map[string]string) WriteOption {
attr := map[string]*dynamodb.AttributeValue{}

for k, v := range fields {
attr[k] = &dynamodb.AttributeValue{S: aws.String(v)}
}

return func(opts *WriteOptions) {
opts.fields = fields
opts.fields = attr
}
}

Expand Down

0 comments on commit aa7c3ab

Please sign in to comment.