Encode the key fields of the given document into a map AttributeValue. pkey and skey are the names of the partition key field and the sort key field. pkey must always be non-empty, but skey may be empty if the collection has no sort key.
(doc driver.Document, pkey, skey string)
| 109 | // pkey and skey are the names of the partition key field and the sort key field. |
| 110 | // pkey must always be non-empty, but skey may be empty if the collection has no sort key. |
| 111 | func encodeDocKeyFields(doc driver.Document, pkey, skey string) (*dyn2Types.AttributeValueMemberM, error) { |
| 112 | m := map[string]dyn2Types.AttributeValue{} |
| 113 | |
| 114 | set := func(fieldName string) error { |
| 115 | fieldVal, err := doc.GetField(fieldName) |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | attrVal, err := encodeValue(fieldVal) |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | m[fieldName] = attrVal |
| 124 | return nil |
| 125 | } |
| 126 | |
| 127 | if err := set(pkey); err != nil { |
| 128 | return nil, err |
| 129 | } |
| 130 | if skey != "" { |
| 131 | if err := set(skey); err != nil { |
| 132 | return nil, err |
| 133 | } |
| 134 | } |
| 135 | return &dyn2Types.AttributeValueMemberM{Value: m}, nil |
| 136 | } |
| 137 | |
| 138 | func encodeValue(v any) (dyn2Types.AttributeValue, error) { |
| 139 | var e encoder |
no test coverage detected