Skip to content

Commit 916f152

Browse files
authored
Consolidate configuration into a TableConfigurable struct. (#84)
* Consolidate configuration into a TableConfigurable struct. * Update CI images. * Update dependencies.
1 parent be01d60 commit 916f152

26 files changed

+217
-402
lines changed

.github/workflows/swift.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
name: Image ${{ matrix.image }}
1212
strategy:
1313
matrix:
14-
image: ["swift:6.1.0-noble", "swift:6.1.0-jammy", "swift:6.0.0-noble"]
14+
image: ["swift:6.1.2-noble", "swift:6.1.2-jammy", "swift:6.0.3-noble"]
1515
runs-on: ubuntu-latest
1616
container:
1717
image: ${{ matrix.image }}

Package.resolved

Lines changed: 41 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// This source file is part of the DynamoDBTables open source project
66
//
7-
// This file is forked from
7+
// This file is forked from
88
// https://github.com/amzn/smoke-dynamodb/Package.swift.
99
// Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
1010
// Licensed under Apache License v2.0
@@ -29,8 +29,11 @@ let swiftSettings: [SwiftSetting] = []
2929
let package = Package(
3030
name: "dynamo-db-tables",
3131
platforms: [
32-
.macOS(.v10_15), .iOS(.v13), .watchOS(.v6), .tvOS(.v13)
33-
],
32+
.macOS(.v12),
33+
.iOS(.v13),
34+
.tvOS(.v13),
35+
.watchOS(.v6),
36+
],
3437
products: [
3538
.library(
3639
name: "DynamoDBTables",
@@ -39,8 +42,8 @@ let package = Package(
3942
dependencies: [
4043
.package(url: "https://github.com/awslabs/aws-sdk-swift.git", from: "1.0.0"),
4144
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
42-
.package(url: "https://github.com/apple/swift-metrics.git", "1.0.0"..<"3.0.0"),
43-
.package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit", from :"0.2.0"),
45+
.package(url: "https://github.com/apple/swift-metrics.git", "1.0.0" ..< "3.0.0"),
46+
.package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit", from: "0.2.0"),
4447
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.53.9"),
4548
.package(url: "https://github.com/apple/swift-syntax", from: "601.0.0"),
4649
],
@@ -64,5 +67,4 @@ let package = Package(
6467
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
6568
],
6669
swiftSettings: swiftSettings),
67-
]
68-
)
70+
])

Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+DynamoDBTableAsync.swift

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,34 @@ public extension AWSDynamoDBCompositePrimaryKeyTable {
9898
}
9999

100100
func polymorphicQuery<ReturnedType: PolymorphicOperationReturnType>(forPartitionKey partitionKey: String,
101-
sortKeyCondition: AttributeCondition?,
102-
consistentRead: Bool) async throws
101+
sortKeyCondition: AttributeCondition?) async throws
103102
-> [ReturnedType]
104103
{
105104
try await self.polymorphicPartialQuery(forPartitionKey: partitionKey,
106105
sortKeyCondition: sortKeyCondition,
107-
exclusiveStartKey: nil,
108-
consistentRead: consistentRead)
106+
exclusiveStartKey: nil)
109107
}
110108

111109
// function to return a future with the results of a query call and all future paginated calls
112110
private func polymorphicPartialQuery<ReturnedType: PolymorphicOperationReturnType>(
113111
forPartitionKey partitionKey: String,
114112
sortKeyCondition: AttributeCondition?,
115-
exclusiveStartKey: String?,
116-
consistentRead: Bool) async throws -> [ReturnedType]
113+
exclusiveStartKey: String?) async throws -> [ReturnedType]
117114
{
118115
let paginatedItems: ([ReturnedType], String?) =
119116
try await polymorphicQuery(forPartitionKey: partitionKey,
120117
sortKeyCondition: sortKeyCondition,
121118
limit: nil,
122119
scanIndexForward: true,
123-
exclusiveStartKey: exclusiveStartKey,
124-
consistentRead: consistentRead)
120+
exclusiveStartKey: exclusiveStartKey)
125121

126122
// if there are more items
127123
if let lastEvaluatedKey = paginatedItems.1 {
128124
// returns a future with all the results from all later paginated calls
129125
let partialResult: [ReturnedType] = try await self.polymorphicPartialQuery(
130126
forPartitionKey: partitionKey,
131127
sortKeyCondition: sortKeyCondition,
132-
exclusiveStartKey: lastEvaluatedKey,
133-
consistentRead: consistentRead)
128+
exclusiveStartKey: lastEvaluatedKey)
134129

135130
// return the results from 'this' call and all later paginated calls
136131
return paginatedItems.0 + partialResult
@@ -143,32 +138,29 @@ public extension AWSDynamoDBCompositePrimaryKeyTable {
143138
func polymorphicQuery<ReturnedType: PolymorphicOperationReturnType>(forPartitionKey partitionKey: String,
144139
sortKeyCondition: AttributeCondition?,
145140
limit: Int?,
146-
exclusiveStartKey: String?,
147-
consistentRead: Bool) async throws
141+
exclusiveStartKey: String?) async throws
148142
-> (items: [ReturnedType], lastEvaluatedKey: String?)
149143
{
150144
try await self.polymorphicQuery(forPartitionKey: partitionKey,
151145
sortKeyCondition: sortKeyCondition,
152146
limit: limit,
153147
scanIndexForward: true,
154-
exclusiveStartKey: exclusiveStartKey,
155-
consistentRead: consistentRead)
148+
exclusiveStartKey: exclusiveStartKey)
156149
}
157150

158151
func polymorphicQuery<ReturnedType: PolymorphicOperationReturnType>(forPartitionKey partitionKey: String,
159152
sortKeyCondition: AttributeCondition?,
160153
limit: Int?,
161154
scanIndexForward: Bool,
162-
exclusiveStartKey: String?,
163-
consistentRead: Bool) async throws
155+
exclusiveStartKey: String?) async throws
164156
-> (items: [ReturnedType], lastEvaluatedKey: String?)
165157
{
166158
let queryInput = try AWSDynamoDB.QueryInput.forSortKeyCondition(partitionKey: partitionKey, targetTableName: targetTableName,
167159
primaryKeyType: ReturnedType.AttributesType.self,
168160
sortKeyCondition: sortKeyCondition, limit: limit,
169161
scanIndexForward: scanIndexForward,
170162
exclusiveStartKey: exclusiveStartKey,
171-
consistentRead: consistentRead)
163+
consistentRead: self.tableConfiguration.consistentRead)
172164

173165
let logMessage = "dynamodb.query with partitionKey: \(partitionKey), " +
174166
"sortKeyCondition: \(sortKeyCondition.debugDescription), and table name \(targetTableName)."
@@ -232,39 +224,34 @@ public extension AWSDynamoDBCompositePrimaryKeyTable {
232224
}
233225

234226
func query<AttributesType, ItemType, TimeToLiveAttributesType>(forPartitionKey partitionKey: String,
235-
sortKeyCondition: AttributeCondition?,
236-
consistentRead: Bool) async throws
227+
sortKeyCondition: AttributeCondition?) async throws
237228
-> [TypedTTLDatabaseItem<AttributesType, ItemType, TimeToLiveAttributesType>]
238229
{
239230
try await self.partialQuery(forPartitionKey: partitionKey,
240231
sortKeyCondition: sortKeyCondition,
241-
exclusiveStartKey: nil,
242-
consistentRead: consistentRead)
232+
exclusiveStartKey: nil)
243233
}
244234

245235
// function to return a future with the results of a query call and all future paginated calls
246236
private func partialQuery<AttributesType, ItemType, TimeToLiveAttributesType>(
247237
forPartitionKey partitionKey: String,
248238
sortKeyCondition: AttributeCondition?,
249-
exclusiveStartKey _: String?,
250-
consistentRead: Bool) async throws -> [TypedTTLDatabaseItem<AttributesType, ItemType, TimeToLiveAttributesType>]
239+
exclusiveStartKey _: String?) async throws -> [TypedTTLDatabaseItem<AttributesType, ItemType, TimeToLiveAttributesType>]
251240
{
252241
let paginatedItems: ([TypedTTLDatabaseItem<AttributesType, ItemType, TimeToLiveAttributesType>], String?) =
253242
try await query(forPartitionKey: partitionKey,
254243
sortKeyCondition: sortKeyCondition,
255244
limit: nil,
256245
scanIndexForward: true,
257-
exclusiveStartKey: nil,
258-
consistentRead: consistentRead)
246+
exclusiveStartKey: nil)
259247

260248
// if there are more items
261249
if let lastEvaluatedKey = paginatedItems.1 {
262250
// returns a future with all the results from all later paginated calls
263251
let partialResult: [TypedTTLDatabaseItem<AttributesType, ItemType, TimeToLiveAttributesType>] = try await self.partialQuery(
264252
forPartitionKey: partitionKey,
265253
sortKeyCondition: sortKeyCondition,
266-
exclusiveStartKey: lastEvaluatedKey,
267-
consistentRead: consistentRead)
254+
exclusiveStartKey: lastEvaluatedKey)
268255

269256
// return the results from 'this' call and all later paginated calls
270257
return paginatedItems.0 + partialResult
@@ -278,16 +265,15 @@ public extension AWSDynamoDBCompositePrimaryKeyTable {
278265
sortKeyCondition: AttributeCondition?,
279266
limit: Int?,
280267
scanIndexForward: Bool,
281-
exclusiveStartKey: String?,
282-
consistentRead: Bool) async throws
268+
exclusiveStartKey: String?) async throws
283269
-> (items: [TypedTTLDatabaseItem<AttributesType, ItemType, TimeToLiveAttributesType>], lastEvaluatedKey: String?)
284270
{
285271
let queryInput = try AWSDynamoDB.QueryInput.forSortKeyCondition(
286272
partitionKey: partitionKey, targetTableName: targetTableName,
287273
primaryKeyType: AttributesType.self,
288274
sortKeyCondition: sortKeyCondition, limit: limit,
289275
scanIndexForward: scanIndexForward, exclusiveStartKey: exclusiveStartKey,
290-
consistentRead: consistentRead)
276+
consistentRead: self.tableConfiguration.consistentRead)
291277

292278
let logMessage = "dynamodb.query with partitionKey: \(partitionKey), " +
293279
"sortKeyCondition: \(sortKeyCondition.debugDescription), and table name \(targetTableName)."

Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift renamed to Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//===----------------------------------------------------------------------===//
2121

2222
//
23-
// DynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift
23+
// AWSDynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift
2424
// DynamoDBTables
2525
//
2626

@@ -60,7 +60,7 @@ func getAttributes(forItem item: TypedTTLDatabaseItem<some Any, some Any, some A
6060
return attributes
6161
}
6262

63-
extension DynamoDBCompositePrimaryKeyTable {
63+
extension AWSDynamoDBCompositePrimaryKeyTable {
6464
func getUpdateExpression<AttributesType, ItemType, TimeToLiveAttributesType>(
6565
tableName: String,
6666
newItem: TypedTTLDatabaseItem<AttributesType, ItemType, TimeToLiveAttributesType>,
@@ -309,7 +309,7 @@ extension DynamoDBCompositePrimaryKeyTable {
309309
/// does not know where the string should end. Therefore, need to escape
310310
/// single quote by doubling it. E.g. 'foo'bar' becomes 'foo''bar'.
311311
private func sanitizeString(_ string: String) -> String {
312-
if self.escapeSingleQuoteInPartiQL {
312+
if self.tableConfiguration.escapeSingleQuoteInPartiQL {
313313
return string.replacingOccurrences(of: "'", with: "''")
314314
} else {
315315
return string

Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+deleteItems.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable {
4343
let statement = try getDeleteExpression(tableName: self.targetTableName,
4444
existingKey: existingKey)
4545

46-
return DynamoDBClientTypes.BatchStatementRequest(consistentRead: true, statement: statement)
46+
return DynamoDBClientTypes.BatchStatementRequest(consistentRead: self.tableConfiguration.consistentRead, statement: statement)
4747
}
4848

4949
let executeInput = BatchExecuteStatementInput(statements: statements)
@@ -64,7 +64,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable {
6464
let statement = try getDeleteExpression(tableName: self.targetTableName,
6565
existingItem: existingItem)
6666

67-
return DynamoDBClientTypes.BatchStatementRequest(consistentRead: true, statement: statement)
67+
return DynamoDBClientTypes.BatchStatementRequest(consistentRead: self.tableConfiguration.consistentRead, statement: statement)
6868
}
6969

7070
let executeInput = BatchExecuteStatementInput(statements: statements)

0 commit comments

Comments
 (0)