dynamo-browse/internal/dynamo-browse/models/items.go
Leon Mika 32ae488066
All checks were successful
ci / build (push) Successful in 3m17s
Moved package to lmika.dev/cmd/dynamo-browse
2025-05-26 22:04:23 +10:00

47 lines
1 KiB
Go

package models
import (
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"lmika.dev/cmd/dynamo-browse/internal/dynamo-browse/models/attrutils"
)
type ItemIndex struct {
Index int
Item Item
}
type Item map[string]types.AttributeValue
// Clone creates a clone of the current item
func (i Item) Clone() Item {
newItem := Item{}
// TODO: should be a deep clone? YES!!
for k, v := range i {
newItem[k] = v
}
return newItem
}
func (i Item) KeyValue(info *TableInfo) map[string]types.AttributeValue {
itemKey := make(map[string]types.AttributeValue)
itemKey[info.Keys.PartitionKey] = i[info.Keys.PartitionKey]
if info.Keys.SortKey != "" {
itemKey[info.Keys.SortKey] = i[info.Keys.SortKey]
}
return itemKey
}
func (i Item) PKSK(info *TableInfo) (pk types.AttributeValue, sk types.AttributeValue) {
pk = i[info.Keys.PartitionKey]
if info.Keys.SortKey != "" {
sk = i[info.Keys.SortKey]
}
return pk, sk
}
func (i Item) AttributeValueAsString(key string) (string, bool) {
return attrutils.AttributeToString(i[key])
}