|
24 | 24 | // DynamoDBTables
|
25 | 25 | //
|
26 | 26 |
|
27 |
| -import Foundation |
28 | 27 | import AWSDynamoDB
|
| 28 | +import Foundation |
29 | 29 | import Logging
|
30 | 30 |
|
31 | 31 | // BatchExecuteStatement has a maximum of 25 statements
|
32 | 32 | private let maximumUpdatesPerExecuteStatement = 25
|
33 | 33 |
|
34 | 34 | /// DynamoDBTable conformance updateItems function
|
35 | 35 | public extension AWSDynamoDBCompositePrimaryKeyTable {
|
36 |
| - |
37 |
| - private func deleteChunkedItems<AttributesType>(_ keys: [CompositePrimaryKey<AttributesType>]) async throws { |
| 36 | + private func deleteChunkedItems(_ keys: [CompositePrimaryKey<some Any>]) async throws { |
38 | 37 | // if there are no keys, there is nothing to update
|
39 | 38 | guard keys.count > 0 else {
|
40 | 39 | return
|
41 | 40 | }
|
42 |
| - |
| 41 | + |
43 | 42 | let statements = try keys.map { existingKey -> DynamoDBClientTypes.BatchStatementRequest in
|
44 | 43 | let statement = try getDeleteExpression(tableName: self.targetTableName,
|
45 | 44 | existingKey: existingKey)
|
46 |
| - |
| 45 | + |
47 | 46 | return DynamoDBClientTypes.BatchStatementRequest(consistentRead: true, statement: statement)
|
48 | 47 | }
|
49 |
| - |
| 48 | + |
50 | 49 | let executeInput = BatchExecuteStatementInput(statements: statements)
|
51 |
| - |
| 50 | + |
52 | 51 | let response = try await self.dynamodb.batchExecuteStatement(input: executeInput)
|
53 | 52 | try throwOnBatchExecuteStatementErrors(response: response)
|
54 | 53 | }
|
55 |
| - |
56 |
| - private func deleteChunkedItems<ItemType: DatabaseItem>(_ existingItems: [ItemType]) async throws { |
| 54 | + |
| 55 | + private func deleteChunkedItems(_ existingItems: [some DatabaseItem]) async throws { |
57 | 56 | // if there are no items, there is nothing to update
|
58 | 57 | guard existingItems.count > 0 else {
|
59 | 58 | return
|
60 | 59 | }
|
61 |
| - |
| 60 | + |
62 | 61 | let statements = try existingItems.map { existingItem -> DynamoDBClientTypes.BatchStatementRequest in
|
63 | 62 | let statement = try getDeleteExpression(tableName: self.targetTableName,
|
64 | 63 | existingItem: existingItem)
|
65 |
| - |
| 64 | + |
66 | 65 | return DynamoDBClientTypes.BatchStatementRequest(consistentRead: true, statement: statement)
|
67 | 66 | }
|
68 |
| - |
| 67 | + |
69 | 68 | let executeInput = BatchExecuteStatementInput(statements: statements)
|
70 |
| - |
| 69 | + |
71 | 70 | let response = try await self.dynamodb.batchExecuteStatement(input: executeInput)
|
72 | 71 | try throwOnBatchExecuteStatementErrors(response: response)
|
73 | 72 | }
|
74 |
| - |
75 |
| - func deleteItems<AttributesType>(forKeys keys: [CompositePrimaryKey<AttributesType>]) async throws { |
| 73 | + |
| 74 | + func deleteItems(forKeys keys: [CompositePrimaryKey<some Any>]) async throws { |
76 | 75 | // BatchExecuteStatement has a maximum of 25 statements
|
77 | 76 | // This function handles pagination internally.
|
78 | 77 | let chunkedKeys = keys.chunked(by: maximumUpdatesPerExecuteStatement)
|
79 | 78 | try await chunkedKeys.concurrentForEach { chunk in
|
80 | 79 | try await self.deleteChunkedItems(chunk)
|
81 | 80 | }
|
82 | 81 | }
|
83 |
| - |
84 |
| - func deleteItems<ItemType: DatabaseItem>(existingItems: [ItemType]) async throws { |
| 82 | + |
| 83 | + func deleteItems(existingItems: [some DatabaseItem]) async throws { |
85 | 84 | // BatchExecuteStatement has a maximum of 25 statements
|
86 | 85 | // This function handles pagination internally.
|
87 | 86 | let chunkedItems = existingItems.chunked(by: maximumUpdatesPerExecuteStatement)
|
|
0 commit comments