Skip to content

Commit

Permalink
Merge pull request #45 from twharmon/additiona-attrs-in-key
Browse files Browse the repository at this point in the history
Additiona attrs in key
  • Loading branch information
twharmon authored Jun 27, 2023
2 parents a7734f0 + ebde33f commit 3223f64
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion dynago.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ func (d *Dynago) key(v Keyer) (map[string]*dynamodb.AttributeValue, error) {
if err != nil {
return nil, fmt.Errorf("d.cachedStruct: %w", err)
}
for _, primKey := range v.PrimaryKeys() {
primKeys := v.PrimaryKeys()
for _, primKey := range primKeys {
for i := 0; i < ty.NumField(); i++ {
if cache[i].attrName == primKey || slices.Contains(cache[i].attrsToCopy, primKey) {
av, err := cache[i].attrVal(val)
Expand All @@ -171,6 +172,21 @@ func (d *Dynago) key(v Keyer) (map[string]*dynamodb.AttributeValue, error) {
}
}
}
if d.config.AdditionalAttrs != nil {
d.config.AdditionalAttrs(m, val)
for k := range m {
isKey := false
for _, pk := range primKeys {
if pk == k {
isKey = true
break
}
}
if !isKey {
delete(m, k)
}
}
}
return m, nil
}

Expand Down

0 comments on commit 3223f64

Please sign in to comment.