@@ -171,23 +171,55 @@ func (ec *EncryptedClient) GetItem(ctx context.Context, input *dynamodb.GetItemI
171
171
172
172
// Query executes a Query operation on DynamoDB and decrypts the returned items.
173
173
func (ec * EncryptedClient ) Query (ctx context.Context , input * dynamodb.QueryInput ) (* dynamodb.QueryOutput , error ) {
174
- encryptedOutput , err := ec .Client .Query (ctx , input )
175
- if err != nil {
176
- return nil , fmt .Errorf ("error querying encrypted items: %v" , err )
177
- }
174
+ paginator := dynamodb .NewQueryPaginator (ec .Client , input )
178
175
179
- // Decrypt the items in the response
180
- for i , item := range encryptedOutput .Items {
181
- decryptedItem , decryptErr := ec .decryptItem (ctx , aws .StringValue (input .TableName ), item )
182
- if decryptErr != nil {
183
- return nil , decryptErr
176
+ var decryptedItems []map [string ]types.AttributeValue
177
+ var lastEvaluatedKey map [string ]types.AttributeValue
178
+
179
+ for paginator .HasMorePages () {
180
+ output , err := paginator .NextPage (ctx )
181
+ if err != nil {
182
+ return nil , fmt .Errorf ("error querying encrypted items: %v" , err )
184
183
}
185
- encryptedOutput .Items [i ] = decryptedItem
184
+
185
+ // Decrypt the items in the response
186
+ for _ , item := range output .Items {
187
+ decryptedItem , decryptErr := ec .decryptItem (ctx , aws .StringValue (input .TableName ), item )
188
+ if decryptErr != nil {
189
+ return nil , decryptErr
190
+ }
191
+ decryptedItems = append (decryptedItems , decryptedItem )
192
+ }
193
+
194
+ lastEvaluatedKey = output .LastEvaluatedKey
186
195
}
187
196
188
- return encryptedOutput , nil
197
+ return & dynamodb.QueryOutput {
198
+ Items : decryptedItems ,
199
+ Count : int32 (len (decryptedItems )),
200
+ ScannedCount : int32 (len (decryptedItems )),
201
+ LastEvaluatedKey : lastEvaluatedKey ,
202
+ }, nil
189
203
}
190
204
205
+ // func (ec *EncryptedClient) Query(ctx context.Context, input *dynamodb.QueryInput) (*dynamodb.QueryOutput, error) {
206
+ // encryptedOutput, err := ec.Client.Query(ctx, input)
207
+ // if err != nil {
208
+ // return nil, fmt.Errorf("error querying encrypted items: %v", err)
209
+ // }
210
+
211
+ // // Decrypt the items in the response
212
+ // for i, item := range encryptedOutput.Items {
213
+ // decryptedItem, decryptErr := ec.decryptItem(ctx, aws.StringValue(input.TableName), item)
214
+ // if decryptErr != nil {
215
+ // return nil, decryptErr
216
+ // }
217
+ // encryptedOutput.Items[i] = decryptedItem
218
+ // }
219
+
220
+ // return encryptedOutput, nil
221
+ // }
222
+
191
223
// Scan executes a Scan operation on DynamoDB and decrypts the returned items.
192
224
func (ec * EncryptedClient ) Scan (ctx context.Context , input * dynamodb.ScanInput ) (* dynamodb.ScanOutput , error ) {
193
225
encryptedOutput , err := ec .Client .Scan (ctx , input )
0 commit comments