MCPcopy Create free account
hub / github.com/google/go-cloud / encodeDocKeyFields

Function encodeDocKeyFields

docstore/awsdynamodb/v2/codec.go:111–136  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
111func 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
138func encodeValue(v any) (dyn2Types.AttributeValue, error) {
139 var e encoder

Callers 3

batchGetMethod · 0.85
newDeleteMethod · 0.85
newUpdateMethod · 0.85

Calls 2

GetFieldMethod · 0.80
encodeValueFunction · 0.70

Tested by

no test coverage detected