2022-03-30 10:55:16 +00:00
|
|
|
package models
|
|
|
|
|
2022-06-02 11:43:14 +00:00
|
|
|
import (
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
|
2022-10-11 11:16:20 +00:00
|
|
|
"github.com/lmika/audax/internal/dynamo-browse/models/attrutils"
|
2022-06-02 11:43:14 +00:00
|
|
|
)
|
2022-03-30 10:55:16 +00:00
|
|
|
|
2022-07-17 12:01:25 +00:00
|
|
|
type ItemIndex struct {
|
|
|
|
Index int
|
|
|
|
Item Item
|
|
|
|
}
|
|
|
|
|
2022-03-30 10:55:16 +00:00
|
|
|
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?
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-05-19 00:48:47 +00:00
|
|
|
func (i Item) AttributeValueAsString(key string) (string, bool) {
|
2022-10-11 11:16:20 +00:00
|
|
|
return attrutils.AttributeToString(i[key])
|
2022-06-02 11:43:14 +00:00
|
|
|
}
|