fix handling of start key in scans on indexes with composite attributes
@@ -236,15 +236,23 @@ func (t {{ $modelName }}Table) scan{{ $modelName }}s(ctx context.Context, input
ConsistentRead: aws.Bool(!input.DisableConsistentRead),
}
if input.StartingAfter != nil {
+ {{- if indexContainsNonCompositeAttribute $xdbConfig $xdbConfig.DynamoDB.KeySchema }}
exclusiveStartKey, err := dynamodbattribute.MarshalMap(input.StartingAfter)
if err != nil {
return fmt.Errorf("error encoding exclusive start key for scan: %%s", err.Error())
}
+ {{- end }}
// must provide only the fields constituting the index
scanInput.ExclusiveStartKey = map[string]*dynamodb.AttributeValue{
{{- range $ks := $xdbConfig.DynamoDB.KeySchema }}
+ {{- if isComposite $xdbConfig $ks.AttributeName }}
+ "{{ $ks.AttributeName }}": &dynamodb.AttributeValue{
+ S: aws.String({{compositeValuePage $xdbConfig $ks.AttributeName "input.StartingAfter"}}),
+ },
+ {{- else }}
"{{ $ks.AttributeName }}": exclusiveStartKey["{{ $ks.AttributeName }}"],
{{- end }}
+ {{- end }}
}
}
var innerErr error
@@ -813,15 +821,23 @@ func (t {{ $modelName }}Table) scan{{ $modelName }}sBy{{ $computedIndexName }}(c
IndexName: aws.String("{{ $gsi.IndexName }}"),
}
if input.StartingAfter != nil {
+ {{- if indexContainsNonCompositeAttribute $xdbConfig $gsi.KeySchema }}
exclusiveStartKey, err := dynamodbattribute.MarshalMap(input.StartingAfter)
if err != nil {
return fmt.Errorf("error encoding exclusive start key for scan: %%s", err.Error())
}
+ {{- end }}
// must provide only the fields constituting the index
scanInput.ExclusiveStartKey = map[string]*dynamodb.AttributeValue{
- {{- range $ks := $xdbConfig.DynamoDB.KeySchema }}
+ {{- range $ks := $gsi.KeySchema }}
+ {{- if isComposite $xdbConfig $ks.AttributeName }}
+ "{{ $ks.AttributeName }}": &dynamodb.AttributeValue{
+ S: aws.String({{compositeValuePage $xdbConfig $ks.AttributeName "input.StartingAfter"}}),
+ },
+ {{- else }}
"{{ $ks.AttributeName }}": exclusiveStartKey["{{ $ks.AttributeName }}"],
{{- end }}
+ {{- end }}
}
}
var innerErr error
