diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 6f564d1..a05113e 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -11,7 +11,7 @@ jobs: name: Image ${{ matrix.image }} strategy: matrix: - image: ["swift:6.1.0-noble", "swift:6.1.0-jammy", "swift:6.0.0-noble"] + image: ["swift:6.1.2-noble", "swift:6.1.2-jammy", "swift:6.0.3-noble"] runs-on: ubuntu-latest container: image: ${{ matrix.image }} diff --git a/Package.resolved b/Package.resolved index 999454a..d597de9 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "23feb994a515c62879f29c830529259b50084197ca5deaea7b1f9b4665d93547", + "originHash" : "a8b37d4d2368118713e93162ea8f45b3e7b9755653b81aba5afd200c9405b6a1", "pins" : [ { "identity" : "aws-crt-swift", @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/awslabs/aws-sdk-swift.git", "state" : { - "revision" : "60cc31a9efc737ededc4266550a3fe08dc8386ca", - "version" : "1.5.7" + "revision" : "58ce4f68a2f20c6cd75922e89a25fb5ee1376d0c", + "version" : "1.5.20" } }, { @@ -46,13 +46,22 @@ "version" : "1.17.1" } }, + { + "identity" : "opentracing-objc", + "kind" : "remoteSourceControl", + "location" : "https://github.com/undefinedlabs/opentracing-objc", + "state" : { + "revision" : "18c1a35ca966236cee0c5a714a51a73ff33384c1", + "version" : "0.5.2" + } + }, { "identity" : "smithy-swift", "kind" : "remoteSourceControl", "location" : "https://github.com/smithy-lang/smithy-swift", "state" : { - "revision" : "8c2b682a15c9cc2efd0f0149c94f562007d538c5", - "version" : "0.149.0" + "revision" : "0385f9a487e80add7d1b7522ffcac9015bca7b9b", + "version" : "0.153.0" } }, { @@ -78,8 +87,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-asn1.git", "state" : { - "revision" : "a54383ada6cecde007d374f58f864e29370ba5c3", - "version" : "1.3.2" + "revision" : "f70225981241859eb4aa1a18a75531d26637c8cc", + "version" : "1.4.0" } }, { @@ -105,8 +114,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-certificates.git", "state" : { - "revision" : "870f4d5fe5fcfedc13f25d70e103150511746404", - "version" : "1.11.0" + "revision" : "c059d9c9d08d6654b9a92dda93d9049a278964c6", + "version" : "1.12.0" } }, { @@ -123,8 +132,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-crypto.git", "state" : { - "revision" : "e8d6eba1fef23ae5b359c46b03f7d94be2f41fed", - "version" : "3.12.3" + "revision" : "334e682869394ee239a57dbe9262bff3cd9495bd", + "version" : "3.14.0" } }, { @@ -132,8 +141,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-http-structured-headers.git", "state" : { - "revision" : "db6eea3692638a65e2124990155cd220c2915903", - "version" : "1.3.0" + "revision" : "1625f271afb04375bf48737a5572613248d0e7a0", + "version" : "1.4.0" } }, { @@ -168,8 +177,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "a5fea865badcb1c993c85b0f0e8d05a4bd2270fb", - "version" : "2.85.0" + "revision" : "1c30f0f2053b654e3d1302492124aa6d242cdba7", + "version" : "2.86.0" } }, { @@ -195,8 +204,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-ssl.git", "state" : { - "revision" : "36b48956eb6c0569215dc15a587b491d2bb36122", - "version" : "2.32.0" + "revision" : "385f5bd783ffbfff46b246a7db7be8e4f04c53bd", + "version" : "2.33.0" } }, { @@ -204,8 +213,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-transport-services.git", "state" : { - "revision" : "decfd235996bc163b44e10b8a24997a3d2104b90", - "version" : "1.25.0" + "revision" : "e645014baea2ec1c2db564410c51a656cf47c923", + "version" : "1.25.1" } }, { @@ -249,8 +258,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-system.git", "state" : { - "revision" : "41daa93a5d229e1548ec86ab527ce4783ca84dda", - "version" : "1.6.0" + "revision" : "890830fff1a577dc83134890c7984020c5f6b43b", + "version" : "1.6.2" } }, { @@ -258,8 +267,17 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/nicklockwood/SwiftFormat", "state" : { - "revision" : "6ebb96ce454ddb036320104a1160350ee9581767", - "version" : "0.56.4" + "revision" : "b83a8f132ff5430f3b6ff7d912baa407caea9e29", + "version" : "0.57.2" + } + }, + { + "identity" : "thrift-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/undefinedlabs/Thrift-Swift", + "state" : { + "revision" : "18ff09e6b30e589ed38f90a1af23e193b8ecef8e", + "version" : "1.1.2" } } ], diff --git a/Package.swift b/Package.swift index 180eb53..c6696b1 100644 --- a/Package.swift +++ b/Package.swift @@ -4,7 +4,7 @@ // // This source file is part of the DynamoDBTables open source project // -// This file is forked from +// This file is forked from // https://github.com/amzn/smoke-dynamodb/Package.swift. // Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. // Licensed under Apache License v2.0 @@ -29,8 +29,11 @@ let swiftSettings: [SwiftSetting] = [] let package = Package( name: "dynamo-db-tables", platforms: [ - .macOS(.v10_15), .iOS(.v13), .watchOS(.v6), .tvOS(.v13) - ], + .macOS(.v12), + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + ], products: [ .library( name: "DynamoDBTables", @@ -39,8 +42,8 @@ let package = Package( dependencies: [ .package(url: "https://github.com/awslabs/aws-sdk-swift.git", from: "1.0.0"), .package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"), - .package(url: "https://github.com/apple/swift-metrics.git", "1.0.0"..<"3.0.0"), - .package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit", from :"0.2.0"), + .package(url: "https://github.com/apple/swift-metrics.git", "1.0.0" ..< "3.0.0"), + .package(url: "https://github.com/JohnSundell/CollectionConcurrencyKit", from: "0.2.0"), .package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.53.9"), .package(url: "https://github.com/apple/swift-syntax", from: "601.0.0"), ], @@ -64,5 +67,4 @@ let package = Package( .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"), ], swiftSettings: swiftSettings), - ] -) + ]) diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+DynamoDBTableAsync.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+DynamoDBTableAsync.swift index 9551689..3ca7ad8 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+DynamoDBTableAsync.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+DynamoDBTableAsync.swift @@ -98,30 +98,26 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { } func polymorphicQuery(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [ReturnedType] { try await self.polymorphicPartialQuery(forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, - exclusiveStartKey: nil, - consistentRead: consistentRead) + exclusiveStartKey: nil) } // function to return a future with the results of a query call and all future paginated calls private func polymorphicPartialQuery( forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, - exclusiveStartKey: String?, - consistentRead: Bool) async throws -> [ReturnedType] + exclusiveStartKey: String?) async throws -> [ReturnedType] { let paginatedItems: ([ReturnedType], String?) = try await polymorphicQuery(forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, limit: nil, scanIndexForward: true, - exclusiveStartKey: exclusiveStartKey, - consistentRead: consistentRead) + exclusiveStartKey: exclusiveStartKey) // if there are more items if let lastEvaluatedKey = paginatedItems.1 { @@ -129,8 +125,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { let partialResult: [ReturnedType] = try await self.polymorphicPartialQuery( forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, - exclusiveStartKey: lastEvaluatedKey, - consistentRead: consistentRead) + exclusiveStartKey: lastEvaluatedKey) // return the results from 'this' call and all later paginated calls return paginatedItems.0 + partialResult @@ -143,24 +138,21 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { func polymorphicQuery(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) { try await self.polymorphicQuery(forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, limit: limit, scanIndexForward: true, - exclusiveStartKey: exclusiveStartKey, - consistentRead: consistentRead) + exclusiveStartKey: exclusiveStartKey) } func polymorphicQuery(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) { let queryInput = try AWSDynamoDB.QueryInput.forSortKeyCondition(partitionKey: partitionKey, targetTableName: targetTableName, @@ -168,7 +160,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { sortKeyCondition: sortKeyCondition, limit: limit, scanIndexForward: scanIndexForward, exclusiveStartKey: exclusiveStartKey, - consistentRead: consistentRead) + consistentRead: self.tableConfiguration.consistentRead) let logMessage = "dynamodb.query with partitionKey: \(partitionKey), " + "sortKeyCondition: \(sortKeyCondition.debugDescription), and table name \(targetTableName)." @@ -232,30 +224,26 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { } func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [TypedTTLDatabaseItem] { try await self.partialQuery(forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, - exclusiveStartKey: nil, - consistentRead: consistentRead) + exclusiveStartKey: nil) } // function to return a future with the results of a query call and all future paginated calls private func partialQuery( forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, - exclusiveStartKey _: String?, - consistentRead: Bool) async throws -> [TypedTTLDatabaseItem] + exclusiveStartKey _: String?) async throws -> [TypedTTLDatabaseItem] { let paginatedItems: ([TypedTTLDatabaseItem], String?) = try await query(forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, limit: nil, scanIndexForward: true, - exclusiveStartKey: nil, - consistentRead: consistentRead) + exclusiveStartKey: nil) // if there are more items if let lastEvaluatedKey = paginatedItems.1 { @@ -263,8 +251,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { let partialResult: [TypedTTLDatabaseItem] = try await self.partialQuery( forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, - exclusiveStartKey: lastEvaluatedKey, - consistentRead: consistentRead) + exclusiveStartKey: lastEvaluatedKey) // return the results from 'this' call and all later paginated calls return paginatedItems.0 + partialResult @@ -278,8 +265,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [TypedTTLDatabaseItem], lastEvaluatedKey: String?) { let queryInput = try AWSDynamoDB.QueryInput.forSortKeyCondition( @@ -287,7 +273,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { primaryKeyType: AttributesType.self, sortKeyCondition: sortKeyCondition, limit: limit, scanIndexForward: scanIndexForward, exclusiveStartKey: exclusiveStartKey, - consistentRead: consistentRead) + consistentRead: self.tableConfiguration.consistentRead) let logMessage = "dynamodb.query with partitionKey: \(partitionKey), " + "sortKeyCondition: \(sortKeyCondition.debugDescription), and table name \(targetTableName)." diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift similarity index 98% rename from Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift rename to Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift index b698afc..1ff7e93 100644 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift @@ -20,7 +20,7 @@ //===----------------------------------------------------------------------===// // -// DynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift +// AWSDynamoDBCompositePrimaryKeyTable+bulkUpdateSupport.swift // DynamoDBTables // @@ -60,7 +60,7 @@ func getAttributes(forItem item: TypedTTLDatabaseItem( tableName: String, newItem: TypedTTLDatabaseItem, @@ -309,7 +309,7 @@ extension DynamoDBCompositePrimaryKeyTable { /// does not know where the string should end. Therefore, need to escape /// single quote by doubling it. E.g. 'foo'bar' becomes 'foo''bar'. private func sanitizeString(_ string: String) -> String { - if self.escapeSingleQuoteInPartiQL { + if self.tableConfiguration.escapeSingleQuoteInPartiQL { return string.replacingOccurrences(of: "'", with: "''") } else { return string diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+deleteItems.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+deleteItems.swift index ebbfcd8..62c8d83 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+deleteItems.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+deleteItems.swift @@ -43,7 +43,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { let statement = try getDeleteExpression(tableName: self.targetTableName, existingKey: existingKey) - return DynamoDBClientTypes.BatchStatementRequest(consistentRead: true, statement: statement) + return DynamoDBClientTypes.BatchStatementRequest(consistentRead: self.tableConfiguration.consistentRead, statement: statement) } let executeInput = BatchExecuteStatementInput(statements: statements) @@ -64,7 +64,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { let statement = try getDeleteExpression(tableName: self.targetTableName, existingItem: existingItem) - return DynamoDBClientTypes.BatchStatementRequest(consistentRead: true, statement: statement) + return DynamoDBClientTypes.BatchStatementRequest(consistentRead: self.tableConfiguration.consistentRead, statement: statement) } let executeInput = BatchExecuteStatementInput(statements: statements) diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+execute.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+execute.swift index d0e8f3b..4fa8f0e 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+execute.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+execute.swift @@ -82,7 +82,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { attributesFilter: attributesFilter, partitionKeyAttributeName: ReturnedType.AttributesType.partitionKeyAttributeName, additionalWhereClause: additionalWhereClause) - let executeInput = ExecuteStatementInput(consistentRead: true, nextToken: nextToken, statement: statement) + let executeInput = ExecuteStatementInput(consistentRead: self.tableConfiguration.consistentRead, nextToken: nextToken, statement: statement) let executeOutput = try await self.dynamodb.executeStatement(input: executeInput) @@ -151,7 +151,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { attributesFilter: attributesFilter, partitionKeyAttributeName: AttributesType.partitionKeyAttributeName, additionalWhereClause: additionalWhereClause) - let executeInput = ExecuteStatementInput(consistentRead: true, nextToken: nextToken, statement: statement) + let executeInput = ExecuteStatementInput(consistentRead: self.tableConfiguration.consistentRead, nextToken: nextToken, statement: statement) let executeOutput = try await self.dynamodb.executeStatement(input: executeInput) diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+getItems.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+getItems.swift index 1290cc7..ab1a465 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+getItems.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+getItems.swift @@ -134,7 +134,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { let retriable = GetItemsRetriable( initialInput: input, dynamodb: self.dynamodb, - retryConfiguration: self.retryConfiguration, + retryConfiguration: self.tableConfiguration.retry, logger: self.logger) return try await retriable.batchGetItem() diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+polymorphicGetItems.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+polymorphicGetItems.swift index 7ad39e8..aafa413 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+polymorphicGetItems.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+polymorphicGetItems.swift @@ -134,7 +134,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { let retriable = PolymorphicGetItemsRetriable( initialInput: input, dynamodb: self.dynamodb, - retryConfiguration: self.retryConfiguration, + retryConfiguration: self.tableConfiguration.retry, logger: self.logger) return try await retriable.batchGetItem() diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+updateItems.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+updateItems.swift index d807fd6..3e89c2a 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+updateItems.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+updateItems.swift @@ -113,8 +113,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { { let statement: String = try entryToStatement(entry) - // doesn't require read consistency as no items are being read - return DynamoDBClientTypes.BatchStatementRequest(consistentRead: false, statement: statement) + return DynamoDBClientTypes.BatchStatementRequest(consistentRead: self.tableConfiguration.consistentRead, statement: statement) } private func writeTransactionItems( @@ -172,7 +171,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { func transactWrite(_ entries: [WriteEntry]) async throws { try await self.transactWrite(entries, constraints: [], - retriesRemaining: self.retryConfiguration.numRetries) + retriesRemaining: self.tableConfiguration.retry.numRetries) } func transactWrite( @@ -180,7 +179,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { constraints: [TransactionConstraintEntry]) async throws { try await self.transactWrite(entries, constraints: constraints, - retriesRemaining: self.retryConfiguration.numRetries) + retriesRemaining: self.tableConfiguration.retry.numRetries) } func polymorphicTransactWrite(_ entries: [WriteEntryType]) async throws { @@ -193,7 +192,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { let inputKeys = entries.map(\.compositePrimaryKey) try await self.polymorphicTransactWrite(transactionInput, inputKeys: inputKeys, - retriesRemaining: self.retryConfiguration.numRetries) + retriesRemaining: self.tableConfiguration.retry.numRetries) } func polymorphicTransactWrite( @@ -293,7 +292,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { result = .failure(DynamoDBTableError.transactionCanceled(reasons: [reason])) } - let retryCount = self.retryConfiguration.numRetries - retriesRemaining + let retryCount = self.tableConfiguration.retry.numRetries - retriesRemaining self.tableMetrics.transactWriteRetryCountRecorder?.record(retryCount) switch result { @@ -310,7 +309,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { retriesRemaining: Int) async throws { // determine the required interval - let retryInterval = Int(self.retryConfiguration.getRetryInterval(retriesRemaining: retriesRemaining)) + let retryInterval = Int(self.tableConfiguration.retry.getRetryInterval(retriesRemaining: retriesRemaining)) logger.warning( "Transaction retried due to conflict. Remaining retries: \(retriesRemaining). Retrying in \(retryInterval) ms.") @@ -396,7 +395,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { result = .failure(DynamoDBTableError.transactionCanceled(reasons: [reason])) } - let retryCount = self.retryConfiguration.numRetries - retriesRemaining + let retryCount = self.tableConfiguration.retry.numRetries - retriesRemaining self.tableMetrics.transactWriteRetryCountRecorder?.record(retryCount) switch result { @@ -412,7 +411,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { inputKeys: [CompositePrimaryKey], retriesRemaining: Int) async throws { // determine the required interval - let retryInterval = Int(self.retryConfiguration.getRetryInterval(retriesRemaining: retriesRemaining)) + let retryInterval = Int(self.tableConfiguration.retry.getRetryInterval(retriesRemaining: retriesRemaining)) logger.warning( "Transaction retried due to conflict. Remaining retries: \(retriesRemaining). Retrying in \(retryInterval) ms.") @@ -434,7 +433,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { let transform: AWSDynamoDBPolymorphicWriteEntryTransform = try entry.handle(context: context) let statement = transform.statement - return DynamoDBClientTypes.BatchStatementRequest(consistentRead: true, statement: statement) + return DynamoDBClientTypes.BatchStatementRequest(consistentRead: self.tableConfiguration.consistentRead, statement: statement) } let executeInput = BatchExecuteStatementInput(statements: statements) @@ -487,7 +486,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { existingItem: existing) } - return DynamoDBClientTypes.BatchStatementRequest(consistentRead: true, statement: statement) + return DynamoDBClientTypes.BatchStatementRequest(consistentRead: self.tableConfiguration.consistentRead, statement: statement) } let executeInput = BatchExecuteStatementInput(statements: statements) diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable.swift index a03b973..cf73a63 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable.swift @@ -41,22 +41,32 @@ public struct AWSDynamoDBTableMetrics { } } +public struct AWSDynamoDBTableConfiguration { + public let consistentRead: Bool + public let escapeSingleQuoteInPartiQL: Bool + public let retry: RetryConfiguration + + public init(consistentRead: Bool = true, escapeSingleQuoteInPartiQL: Bool = false, + retry: RetryConfiguration = .default) + { + self.consistentRead = consistentRead + self.escapeSingleQuoteInPartiQL = escapeSingleQuoteInPartiQL + self.retry = retry + } +} + public struct AWSDynamoDBCompositePrimaryKeyTable: DynamoDBCompositePrimaryKeyTable { let dynamodb: AWSDynamoDB.DynamoDBClient let targetTableName: String - public let consistentRead: Bool - public let escapeSingleQuoteInPartiQL: Bool + public let tableConfiguration: AWSDynamoDBTableConfiguration public let tableMetrics: AWSDynamoDBTableMetrics - let retryConfiguration: RetryConfiguration let logger: Logging.Logger public init(tableName: String, region: Swift.String, awsCredentialIdentityResolver: (any SmithyIdentity.AWSCredentialIdentityResolver)? = nil, httpClientConfiguration: ClientRuntime.HttpClientConfiguration? = nil, - consistentRead: Bool = true, - escapeSingleQuoteInPartiQL: Bool = false, + tableConfiguration: AWSDynamoDBTableConfiguration = .init(), tableMetrics: AWSDynamoDBTableMetrics = .init(), - retryConfiguration: RetryConfiguration = .default, logger: Logging.Logger? = nil) throws { self.logger = logger ?? Logging.Logger(label: "AWSDynamoDBCompositePrimaryKeyTable") @@ -66,29 +76,23 @@ public struct AWSDynamoDBCompositePrimaryKeyTable: DynamoDBCompositePrimaryKeyTa httpClientConfiguration: httpClientConfiguration) self.dynamodb = AWSDynamoDB.DynamoDBClient(config: config) self.targetTableName = tableName - self.consistentRead = consistentRead - self.escapeSingleQuoteInPartiQL = escapeSingleQuoteInPartiQL + self.tableConfiguration = tableConfiguration self.tableMetrics = tableMetrics - self.retryConfiguration = retryConfiguration self.logger.trace("AWSDynamoDBCompositePrimaryKeyTable created with region '\(region)'") } public init(tableName: String, client: AWSDynamoDB.DynamoDBClient, - consistentRead: Bool = true, - escapeSingleQuoteInPartiQL: Bool = false, + tableConfiguration: AWSDynamoDBTableConfiguration = .init(), tableMetrics: AWSDynamoDBTableMetrics = .init(), - retryConfiguration: RetryConfiguration = .default, logger: Logging.Logger? = nil) { self.logger = logger ?? Logging.Logger(label: "AWSDynamoDBCompositePrimaryKeyTable") self.dynamodb = client self.targetTableName = tableName - self.consistentRead = consistentRead - self.escapeSingleQuoteInPartiQL = escapeSingleQuoteInPartiQL + self.tableConfiguration = tableConfiguration self.tableMetrics = tableMetrics - self.retryConfiguration = retryConfiguration self.logger.trace("AWSDynamoDBCompositePrimaryKeyTable created with existing client") } @@ -138,7 +142,7 @@ extension AWSDynamoDBCompositePrimaryKeyTable { let attributeValue = try DynamoDBEncoder().encode(key) if case let .m(keyAttributes) = attributeValue { - return AWSDynamoDB.GetItemInput(consistentRead: self.consistentRead, + return AWSDynamoDB.GetItemInput(consistentRead: self.tableConfiguration.consistentRead, key: keyAttributes, tableName: self.targetTableName) } else { @@ -159,7 +163,7 @@ extension AWSDynamoDBCompositePrimaryKeyTable { } } - let keysAndAttributes = DynamoDBClientTypes.KeysAndAttributes(consistentRead: self.consistentRead, + let keysAndAttributes = DynamoDBClientTypes.KeysAndAttributes(consistentRead: self.tableConfiguration.consistentRead, keys: keys) return AWSDynamoDB.BatchGetItemInput(requestItems: [self.targetTableName: keysAndAttributes]) diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeysProjection+DynamoDBKeysProjectionAsync.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeysProjection+DynamoDBKeysProjectionAsync.swift index 5b1e0a6..590b3e4 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeysProjection+DynamoDBKeysProjectionAsync.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeysProjection+DynamoDBKeysProjectionAsync.swift @@ -93,7 +93,7 @@ public extension AWSDynamoDBCompositePrimaryKeysProjection { primaryKeyType: AttributesType.self, sortKeyCondition: sortKeyCondition, limit: limit, scanIndexForward: scanIndexForward, exclusiveStartKey: exclusiveStartKey, - consistentRead: false) + consistentRead: self.tableConfiguration.consistentRead) let logMessage = "dynamodb.query with partitionKey: \(partitionKey), " + "sortKeyCondition: \(sortKeyCondition.debugDescription), and table name \(targetTableName)." diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeysProjection.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeysProjection.swift index a027d02..b25f525 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeysProjection.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeysProjection.swift @@ -34,6 +34,7 @@ import SmithyIdentity public struct AWSDynamoDBCompositePrimaryKeysProjection: DynamoDBCompositePrimaryKeysProjection { let dynamodb: AWSDynamoDB.DynamoDBClient let targetTableName: String + public let tableConfiguration: AWSDynamoDBTableConfiguration let logger: Logging.Logger class QueryPaginationResults { @@ -44,6 +45,7 @@ public struct AWSDynamoDBCompositePrimaryKeysProjection: DynamoDBCompositePrimar public init(tableName: String, region: Swift.String, awsCredentialIdentityResolver: (any SmithyIdentity.AWSCredentialIdentityResolver)? = nil, httpClientConfiguration: ClientRuntime.HttpClientConfiguration? = nil, + tableConfiguration: AWSDynamoDBTableConfiguration = .init(), logger: Logging.Logger? = nil) throws { self.logger = logger ?? Logging.Logger(label: "AWSDynamoDBCompositePrimaryKeysProjection") @@ -52,6 +54,7 @@ public struct AWSDynamoDBCompositePrimaryKeysProjection: DynamoDBCompositePrimar region: region, httpClientConfiguration: httpClientConfiguration) self.dynamodb = AWSDynamoDB.DynamoDBClient(config: config) + self.tableConfiguration = tableConfiguration self.targetTableName = tableName self.logger.trace("AWSDynamoDBCompositePrimaryKeysProjection created with region '\(region)'") @@ -59,10 +62,12 @@ public struct AWSDynamoDBCompositePrimaryKeysProjection: DynamoDBCompositePrimar public init(tableName: String, client: AWSDynamoDB.DynamoDBClient, + tableConfiguration: AWSDynamoDBTableConfiguration = .init(), logger: Logging.Logger? = nil) { self.logger = logger ?? Logging.Logger(label: "AWSDynamoDBCompositePrimaryKeysProjection") self.dynamodb = client + self.tableConfiguration = tableConfiguration self.targetTableName = tableName self.logger.trace("AWSDynamoDBCompositePrimaryKeysProjection created with existing client") diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyGSILogic.swift b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyGSILogic.swift index ec8df9e..d3e33fd 100644 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyGSILogic.swift +++ b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyGSILogic.swift @@ -70,8 +70,8 @@ public protocol DynamoDBCompositePrimaryKeyGSILogic { * Called when an item is delete on the main table. Can be used to also delete the corresponding item on the GSI. */ - func onDeleteItem(forKey key: CompositePrimaryKey, - gsiDataStore: InMemoryDynamoDBCompositePrimaryKeyTable) async throws + func onDeleteItem(forKey key: CompositePrimaryKey, + gsiDataStore: InMemoryDynamoDBCompositePrimaryKeyTable) async throws /** * Called when an transact write in the main table. Can be used to also transact write the corresponding item on the GSI. diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+conditionallyUpdateItem.swift b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+conditionallyUpdateItem.swift index c60a3a8..0b8a825 100644 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+conditionallyUpdateItem.swift +++ b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+conditionallyUpdateItem.swift @@ -60,25 +60,6 @@ public extension DynamoDBCompositePrimaryKeyTable { updatedItemProvider: updatedItemProvider) } - // Explicitly specify an overload with sync updatedPayloadProvider - // to avoid the compiler matching a call site with such a provider with the EventLoopFuture-returning overload. - func conditionallyUpdateItem( - forKey key: CompositePrimaryKey, - withRetries retries: Int = 10, - timeToLiveAttributesType _: TimeToLiveAttributesType.Type = StandardTimeToLiveAttributes.self, - updatedPayloadProvider: @escaping (ItemType) throws -> ItemType) async throws - { - let updatedItemProvider: (TypedTTLDatabaseItem) async throws - -> TypedTTLDatabaseItem = { existingItem in - let updatedPayload = try updatedPayloadProvider(existingItem.rowValue) - return existingItem.createUpdatedItem(withValue: updatedPayload) - } - try await self.conditionallyUpdateItemInternal( - forKey: key, - withRetries: retries, - updatedItemProvider: updatedItemProvider) - } - /** Method to conditionally update an item at the specified key for a number of retries. This method is useful for database rows that may be updated simultaneously by different clients @@ -105,20 +86,6 @@ public extension DynamoDBCompositePrimaryKeyTable { updatedItemProvider: updatedItemProvider) } - // Explicitly specify an overload with sync updatedItemProvider - // to avoid the compiler matching a call site with such a provider with the EventLoopFuture-returning overload. - func conditionallyUpdateItem( - forKey key: CompositePrimaryKey, - withRetries retries: Int = 10, - updatedItemProvider: @escaping (TypedTTLDatabaseItem) throws - -> TypedTTLDatabaseItem) async throws - { - try await self.conditionallyUpdateItemInternal( - forKey: key, - withRetries: retries, - updatedItemProvider: updatedItemProvider) - } - private func conditionallyUpdateItemInternal( forKey key: CompositePrimaryKey, withRetries retries: Int = 10, diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+consistentReadQuery.swift b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+consistentReadQuery.swift deleted file mode 100644 index 03177bf..0000000 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+consistentReadQuery.swift +++ /dev/null @@ -1,91 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the DynamoDBTables open source project -// -// This file is forked from -// https://github.com/amzn/smoke-dynamodb/tree/smoke-dynamodb-3.x/Sources/SmokeDynamoDB/DynamoDBCompositePrimaryKeyTable+consistentReadQuery.swift -// Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// Licensed under Apache License v2.0 -// -// Changes specified by -// https://github.com/swift-server-community/dynamo-db-tables/compare/9ab0e7a..main -// Copyright (c) 2024 the DynamoDBTables authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of DynamoDBTables authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -// -// DynamoDBCompositePrimaryKeyTable+consistentReadQuery.swift -// DynamoDBTables -// - -import AWSDynamoDB -import Foundation - -public extension DynamoDBCompositePrimaryKeyTable { - func polymorphicQuery(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?) async throws - -> [ReturnedType] - { - try await self.polymorphicQuery(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - consistentRead: self.consistentRead) - } - - func polymorphicQuery(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - limit: Int?, - exclusiveStartKey: String?) async throws - -> ([ReturnedType], String?) - { - try await self.polymorphicQuery(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - limit: limit, - exclusiveStartKey: exclusiveStartKey, - consistentRead: self.consistentRead) - } - - func polymorphicQuery(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - limit: Int?, - scanIndexForward: Bool, - exclusiveStartKey: String?) async throws - -> ([ReturnedType], String?) - { - try await self.polymorphicQuery(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - limit: limit, - scanIndexForward: scanIndexForward, - exclusiveStartKey: exclusiveStartKey, - consistentRead: self.consistentRead) - } - - func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?) async throws - -> [TypedTTLDatabaseItem] - { - try await self.query(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - consistentRead: self.consistentRead) - } - - func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - limit: Int?, - scanIndexForward: Bool, - exclusiveStartKey: String?) async throws - -> ([TypedTTLDatabaseItem], String?) - { - try await self.query(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - limit: limit, - scanIndexForward: scanIndexForward, - exclusiveStartKey: exclusiveStartKey, - consistentRead: self.consistentRead) - } -} diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift index deafc2a..73b631a 100644 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift +++ b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift @@ -106,16 +106,6 @@ public enum WriteEntry = WriteEntry public protocol DynamoDBCompositePrimaryKeyTable { - // This property doesn't really belong on the protocol but provides - // access to the property for the protocol's extensions - var consistentRead: Bool { get } - - /** - * PartiQL string attributes cannot contain single quotes. Otherwise, PartiQL statement is consider to be invalid. - * This property controls if single quotes are escaped while formatting PartiQL statements. - */ - var escapeSingleQuoteInPartiQL: Bool { get } - /** * Insert item is a non-destructive API. If an item already exists with the specified key this * API should fail. @@ -143,8 +133,8 @@ public protocol DynamoDBCompositePrimaryKeyTable { */ func transactWrite(_ entries: [WriteEntry]) async throws - func polymorphicTransactWrite( - _ entries: [WriteEntryType]) async throws + func polymorphicTransactWrite( + _ entries: [some PolymorphicWriteEntry]) async throws /** * Provides the ability to bulk write database rows in a transaction. @@ -169,7 +159,7 @@ public protocol DynamoDBCompositePrimaryKeyTable { func bulkWriteWithFallback(_ entries: [WriteEntry]) async throws - func polymorphicBulkWrite(_ entries: [WriteEntryType]) async throws + func polymorphicBulkWrite(_ entries: [some PolymorphicWriteEntry]) async throws /** * Retrieves an item from the database table. Returns nil if the item doesn't exist. @@ -188,7 +178,7 @@ public protocol DynamoDBCompositePrimaryKeyTable { * Removes an item from the database table. Is an idempotent operation; running it multiple times * on the same item or attribute does not result in an error response. */ - func deleteItem(forKey key: CompositePrimaryKey) async throws + func deleteItem(forKey key: CompositePrimaryKey) async throws /** * Removes an item from the database table. Is an idempotent operation; running it multiple times @@ -201,7 +191,7 @@ public protocol DynamoDBCompositePrimaryKeyTable { * Removes items from the database table. Is an idempotent operation; running it multiple times * on the same item or attribute does not result in an error response. */ - func deleteItems(forKeys keys: [CompositePrimaryKey]) async throws + func deleteItems(forKeys keys: [CompositePrimaryKey]) async throws /** * Removes items from the database table. Is an idempotent operation; running it multiple times @@ -217,8 +207,7 @@ public protocol DynamoDBCompositePrimaryKeyTable { the query. */ func polymorphicQuery(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [ReturnedType] /** @@ -229,8 +218,7 @@ public protocol DynamoDBCompositePrimaryKeyTable { func polymorphicQuery(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) /** @@ -242,8 +230,7 @@ public protocol DynamoDBCompositePrimaryKeyTable { sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) /** @@ -287,8 +274,7 @@ public protocol DynamoDBCompositePrimaryKeyTable { the query. */ func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [TypedTTLDatabaseItem] /** @@ -301,8 +287,7 @@ public protocol DynamoDBCompositePrimaryKeyTable { sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [TypedTTLDatabaseItem], lastEvaluatedKey: String?) /** @@ -330,17 +315,3 @@ public protocol DynamoDBCompositePrimaryKeyTable { additionalWhereClause: String?, nextToken: String?) async throws -> (items: [TypedTTLDatabaseItem], lastEvaluatedKey: String?) } - -public extension DynamoDBCompositePrimaryKeyTable { - // provide a default value for the table's `consistentRead` - // maintains backwards compatibility - var consistentRead: Bool { - true - } - - // provide a default value for the table's `escapeSingleQuoteInPartiQL` - // maintains backwards compatibility - var escapeSingleQuoteInPartiQL: Bool { - false - } -} diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTableHistoricalItemExtensions.swift b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTableHistoricalItemExtensions.swift index 1c96dff..94cdc17 100644 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTableHistoricalItemExtensions.swift +++ b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTableHistoricalItemExtensions.swift @@ -135,23 +135,6 @@ public extension DynamoDBCompositePrimaryKeyTable { withRetries: retries) } - // Explicitly specify an overload with sync updatedPayloadProvider - // to avoid the compiler matching a call site with such a provider with the EventLoopFuture-returning overload. - func conditionallyUpdateItemWithHistoricalRow( - compositePrimaryKey: CompositePrimaryKey, - primaryItemProvider: @escaping (TypedTTLDatabaseItem) throws -> - TypedTTLDatabaseItem, - historicalItemProvider: @escaping (TypedTTLDatabaseItem) -> - TypedTTLDatabaseItem, - withRetries retries: Int = 10) async throws -> TypedTTLDatabaseItem - { - try await self.conditionallyUpdateItemWithHistoricalRowInternal( - compositePrimaryKey: compositePrimaryKey, - primaryItemProvider: primaryItemProvider, - historicalItemProvider: historicalItemProvider, - withRetries: retries) - } - private func conditionallyUpdateItemWithHistoricalRowInternal( compositePrimaryKey: CompositePrimaryKey, primaryItemProvider: @escaping (TypedTTLDatabaseItem) async throws -> @@ -182,13 +165,13 @@ public extension DynamoDBCompositePrimaryKeyTable { try await self.updateItemWithHistoricalRow(primaryItem: updatedItem, existingItem: existingItem, historicalItem: historicalItem) + + return updatedItem } catch DynamoDBTableError.conditionalCheckFailed { // try again - return try await self.conditionallyUpdateItemWithHistoricalRow(compositePrimaryKey: compositePrimaryKey, - primaryItemProvider: primaryItemProvider, - historicalItemProvider: historicalItemProvider, withRetries: retries - 1) + return try await self.conditionallyUpdateItemWithHistoricalRowInternal(compositePrimaryKey: compositePrimaryKey, + primaryItemProvider: primaryItemProvider, + historicalItemProvider: historicalItemProvider, withRetries: retries - 1) } - - return updatedItem } } diff --git a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable+query.swift b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable+query.swift index c0e068c..127edc1 100644 --- a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable+query.swift +++ b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable+query.swift @@ -73,8 +73,7 @@ public extension InMemoryDynamoDBCompositePrimaryKeyTable { } func polymorphicQuery(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead _: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [ReturnedType] { var items: [ReturnedType] = [] @@ -135,30 +134,26 @@ public extension InMemoryDynamoDBCompositePrimaryKeyTable { func polymorphicQuery(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) { try await self.polymorphicQuery(forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, limit: limit, scanIndexForward: true, - exclusiveStartKey: exclusiveStartKey, - consistentRead: consistentRead) + exclusiveStartKey: exclusiveStartKey) } func polymorphicQuery(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) { // get all the results let rawItems: [ReturnedType] = try await polymorphicQuery(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - consistentRead: consistentRead) + sortKeyCondition: sortKeyCondition) let items: [ReturnedType] if !scanIndexForward { @@ -193,8 +188,7 @@ public extension InMemoryDynamoDBCompositePrimaryKeyTable { } func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead _: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [TypedTTLDatabaseItem] { var items: [TypedTTLDatabaseItem] = [] @@ -264,14 +258,12 @@ public extension InMemoryDynamoDBCompositePrimaryKeyTable { sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [TypedTTLDatabaseItem], lastEvaluatedKey: String?) { // get all the results let rawItems: [TypedTTLDatabaseItem] = try await query(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - consistentRead: consistentRead) + sortKeyCondition: sortKeyCondition) let items: [TypedTTLDatabaseItem] if !scanIndexForward { diff --git a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable.swift b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable.swift index b453895..993fc08 100644 --- a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable.swift +++ b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable.swift @@ -41,22 +41,19 @@ public protocol InMemoryTransactionDelegate: Sendable { /** Inject errors into a `transactWrite` or `polymorphicTransactWrite` call. */ - func injectErrors( - inputKeys: [CompositePrimaryKey?], table: InMemoryDynamoDBCompositePrimaryKeyTable) async throws -> [DynamoDBTableError] + func injectErrors( + inputKeys: [CompositePrimaryKey?], table: InMemoryDynamoDBCompositePrimaryKeyTable) async throws -> [DynamoDBTableError] } public struct InMemoryDynamoDBCompositePrimaryKeyTable: DynamoDBCompositePrimaryKeyTable, Sendable { - public let escapeSingleQuoteInPartiQL: Bool public let transactionDelegate: InMemoryTransactionDelegate? public let executeItemFilter: ExecuteItemFilterType? let storeWrapper: InMemoryDynamoDBCompositePrimaryKeyTableStore public init(executeItemFilter: ExecuteItemFilterType? = nil, - escapeSingleQuoteInPartiQL: Bool = false, transactionDelegate: InMemoryTransactionDelegate? = nil) { self.storeWrapper = InMemoryDynamoDBCompositePrimaryKeyTableStore() - self.escapeSingleQuoteInPartiQL = escapeSingleQuoteInPartiQL self.transactionDelegate = transactionDelegate self.executeItemFilter = executeItemFilter } diff --git a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTableWithIndex.swift b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTableWithIndex.swift index 5486122..488dcc9 100644 --- a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTableWithIndex.swift +++ b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTableWithIndex.swift @@ -165,8 +165,7 @@ public struct InMemoryDynamoDBCompositePrimaryKeyTableWithIndex(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [ReturnedType] { // if this is querying an index @@ -178,21 +177,18 @@ public struct InMemoryDynamoDBCompositePrimaryKeyTableWithIndex(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) { // if this is querying an index @@ -204,20 +200,19 @@ public struct InMemoryDynamoDBCompositePrimaryKeyTableWithIndex(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) { // if this is querying an index @@ -229,14 +224,12 @@ public struct InMemoryDynamoDBCompositePrimaryKeyTableWithIndex( @@ -292,8 +285,7 @@ public struct InMemoryDynamoDBCompositePrimaryKeyTableWithIndex(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [TypedTTLDatabaseItem] { // if this is querying an index @@ -305,22 +297,19 @@ public struct InMemoryDynamoDBCompositePrimaryKeyTableWithIndex(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [TypedTTLDatabaseItem], lastEvaluatedKey: String?) { // if this is querying an index @@ -332,14 +321,12 @@ public struct InMemoryDynamoDBCompositePrimaryKeyTableWithIndex( diff --git a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjectionStore.swift b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjectionStore.swift index 6ea1f05..edbf258 100644 --- a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjectionStore.swift +++ b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjectionStore.swift @@ -31,14 +31,14 @@ import Foundation // MARK: - Store implementation actor InMemoryDynamoDBCompositePrimaryKeysProjectionStore { - public var keys: [TypeErasedCompositePrimaryKey] = [] + var keys: [TypeErasedCompositePrimaryKey] = [] - public init(keys: [CompositePrimaryKey] = []) { + init(keys: [CompositePrimaryKey] = []) { self.keys = keys.map { .init(partitionKey: $0.partitionKey, sortKey: $0.sortKey) } } - public func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?) async throws + func query(forPartitionKey partitionKey: String, + sortKeyCondition: AttributeCondition?) async throws -> [CompositePrimaryKey] { var items: [CompositePrimaryKey] = [] @@ -100,10 +100,10 @@ actor InMemoryDynamoDBCompositePrimaryKeysProjectionStore { return items } - public func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - limit: Int?, - exclusiveStartKey: String?) async throws + func query(forPartitionKey partitionKey: String, + sortKeyCondition: AttributeCondition?, + limit: Int?, + exclusiveStartKey: String?) async throws -> (keys: [CompositePrimaryKey], lastEvaluatedKey: String?) { try await self.query(forPartitionKey: partitionKey, @@ -113,11 +113,11 @@ actor InMemoryDynamoDBCompositePrimaryKeysProjectionStore { exclusiveStartKey: exclusiveStartKey) } - public func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - limit: Int?, - scanIndexForward: Bool, - exclusiveStartKey: String?) async throws + func query(forPartitionKey partitionKey: String, + sortKeyCondition: AttributeCondition?, + limit: Int?, + scanIndexForward: Bool, + exclusiveStartKey: String?) async throws -> (keys: [CompositePrimaryKey], lastEvaluatedKey: String?) { // get all the results diff --git a/Sources/DynamoDBTables/PolymorphicOperationReturnType.swift b/Sources/DynamoDBTables/PolymorphicOperationReturnType.swift index 82590a5..464c6ce 100644 --- a/Sources/DynamoDBTables/PolymorphicOperationReturnType.swift +++ b/Sources/DynamoDBTables/PolymorphicOperationReturnType.swift @@ -76,7 +76,7 @@ public struct PolymorphicOperationReturnOption: Decodable { - public let decodedValue: ReturnType + let decodedValue: ReturnType enum CodingKeys: String, CodingKey { case rowType = "RowType" @@ -86,7 +86,7 @@ struct ReturnTypeDecodable: Decodabl self.decodedValue = decodedValue } - public init(from decoder: Decoder) throws { + init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) let storedRowTypeName = try values.decode(String.self, forKey: .rowType) diff --git a/Sources/DynamoDBTables/PolymorphicWriteEntry.swift b/Sources/DynamoDBTables/PolymorphicWriteEntry.swift index 9db55be..0f0748a 100644 --- a/Sources/DynamoDBTables/PolymorphicWriteEntry.swift +++ b/Sources/DynamoDBTables/PolymorphicWriteEntry.swift @@ -31,8 +31,8 @@ import AWSDynamoDB public protocol PolymorphicWriteEntryTransform { associatedtype TableType - init( - _ entry: WriteEntry, table: TableType) throws + init( + _ entry: WriteEntry, table: TableType) throws } // Conforming types are provided by the Table implementation to convert a `WriteEntry` into @@ -40,8 +40,8 @@ public protocol PolymorphicWriteEntryTransform { public protocol PolymorphicTransactionConstraintTransform { associatedtype TableType - init( - _ entry: TransactionConstraintEntry, table: TableType) throws + init( + _ entry: TransactionConstraintEntry, table: TableType) throws } // Conforming types are provided by the application to express the different possible write entries @@ -93,12 +93,12 @@ public protocol PolymorphicWriteEntryContext { associatedtype WriteEntryTransformType: PolymorphicWriteEntryTransform associatedtype WriteTransactionConstraintType: PolymorphicTransactionConstraintTransform - func transform( - _ entry: WriteEntry) throws + func transform( + _ entry: WriteEntry) throws -> WriteEntryTransformType - func transform( - _ entry: TransactionConstraintEntry) throws + func transform( + _ entry: TransactionConstraintEntry) throws -> WriteTransactionConstraintType } diff --git a/Sources/DynamoDBTables/SimulateConcurrencyDynamoDBCompositePrimaryKeyTable.swift b/Sources/DynamoDBTables/SimulateConcurrencyDynamoDBCompositePrimaryKeyTable.swift index 3c1a19a..7a75d0e 100644 --- a/Sources/DynamoDBTables/SimulateConcurrencyDynamoDBCompositePrimaryKeyTable.swift +++ b/Sources/DynamoDBTables/SimulateConcurrencyDynamoDBCompositePrimaryKeyTable.swift @@ -186,37 +186,32 @@ public class SimulateConcurrencyDynamoDBCompositePrimaryKeyTable: DynamoDBCompos } public func polymorphicQuery(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [ReturnedType] { // simply delegate to the wrapped implementation try await self.wrappedDynamoDBTable.polymorphicQuery(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - consistentRead: consistentRead) + sortKeyCondition: sortKeyCondition) } public func polymorphicQuery(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) { // simply delegate to the wrapped implementation try await self.wrappedDynamoDBTable.polymorphicQuery(forPartitionKey: partitionKey, sortKeyCondition: sortKeyCondition, limit: limit, - exclusiveStartKey: exclusiveStartKey, - consistentRead: consistentRead) + exclusiveStartKey: exclusiveStartKey) } public func polymorphicQuery(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [ReturnedType], lastEvaluatedKey: String?) { // simply delegate to the wrapped implementation @@ -224,8 +219,7 @@ public class SimulateConcurrencyDynamoDBCompositePrimaryKeyTable: DynamoDBCompos sortKeyCondition: sortKeyCondition, limit: limit, scanIndexForward: scanIndexForward, - exclusiveStartKey: exclusiveStartKey, - consistentRead: consistentRead) + exclusiveStartKey: exclusiveStartKey) } public func polymorphicExecute( @@ -287,22 +281,19 @@ public class SimulateConcurrencyDynamoDBCompositePrimaryKeyTable: DynamoDBCompos } public func query(forPartitionKey partitionKey: String, - sortKeyCondition: AttributeCondition?, - consistentRead: Bool) async throws + sortKeyCondition: AttributeCondition?) async throws -> [TypedTTLDatabaseItem] { // simply delegate to the wrapped implementation try await self.wrappedDynamoDBTable.query(forPartitionKey: partitionKey, - sortKeyCondition: sortKeyCondition, - consistentRead: consistentRead) + sortKeyCondition: sortKeyCondition) } public func query(forPartitionKey partitionKey: String, sortKeyCondition: AttributeCondition?, limit: Int?, scanIndexForward: Bool, - exclusiveStartKey: String?, - consistentRead: Bool) async throws + exclusiveStartKey: String?) async throws -> (items: [TypedTTLDatabaseItem], lastEvaluatedKey: String?) { // simply delegate to the wrapped implementation @@ -310,7 +301,6 @@ public class SimulateConcurrencyDynamoDBCompositePrimaryKeyTable: DynamoDBCompos sortKeyCondition: sortKeyCondition, limit: limit, scanIndexForward: scanIndexForward, - exclusiveStartKey: exclusiveStartKey, - consistentRead: consistentRead) + exclusiveStartKey: exclusiveStartKey) } } diff --git a/Tests/DynamoDBTablesTests/TypedDatabaseItem+RowWithItemVersionProtocolTests.swift b/Tests/DynamoDBTablesTests/TypedDatabaseItem+RowWithItemVersionProtocolTests.swift index 9e014d8..2498ee3 100644 --- a/Tests/DynamoDBTablesTests/TypedDatabaseItem+RowWithItemVersionProtocolTests.swift +++ b/Tests/DynamoDBTablesTests/TypedDatabaseItem+RowWithItemVersionProtocolTests.swift @@ -115,6 +115,11 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { } } + func getTable(escapeSingleQuoteInPartiQL: Bool = false) throws -> AWSDynamoDBCompositePrimaryKeyTable { + try AWSDynamoDBCompositePrimaryKeyTable(tableName: "DummyTable", region: "us-west-2", + tableConfiguration: .init(escapeSingleQuoteInPartiQL: escapeSingleQuoteInPartiQL)) + } + @Test func stringFieldDifference() throws { let theStruct = TestTypeA(firstly: "firstly", secondly: "secondly") @@ -126,7 +131,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -147,7 +152,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable(escapeSingleQuoteInPartiQL: true) + let table = try getTable(escapeSingleQuoteInPartiQL: true) let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -168,7 +173,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -190,7 +195,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -212,7 +217,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable(escapeSingleQuoteInPartiQL: true) + let table = try getTable(escapeSingleQuoteInPartiQL: true) let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -233,7 +238,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -259,7 +264,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -286,7 +291,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable(escapeSingleQuoteInPartiQL: true) + let table = try getTable(escapeSingleQuoteInPartiQL: true) let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -309,7 +314,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -330,7 +335,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -351,7 +356,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -380,7 +385,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -401,7 +406,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -422,7 +427,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -443,7 +448,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -464,7 +469,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = databaseItemA.createUpdatedItem(withValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let differences = try table.diffItems(newItem: databaseItemB, existingItem: databaseItemA) @@ -486,7 +491,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let expression = try table.getUpdateExpression(tableName: tableName, newItem: databaseItemB, @@ -513,7 +518,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable(escapeSingleQuoteInPartiQL: true) + let table = try getTable(escapeSingleQuoteInPartiQL: true) let expression = try table.getUpdateExpression(tableName: tableName, newItem: databaseItemB, @@ -538,7 +543,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let expression = try table.getUpdateExpression(tableName: tableName, newItem: databaseItemB, @@ -561,7 +566,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) let databaseItemB = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadB) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let expression = try table.getUpdateExpression(tableName: tableName, newItem: databaseItemB, @@ -582,7 +587,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { sortKey: "sortKey") let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let expression = try table.getDeleteExpression(tableName: tableName, existingItem: databaseItemA) @@ -601,7 +606,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { sortKey: "sort'''Key") let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) - let table = InMemoryDynamoDBCompositePrimaryKeyTable(escapeSingleQuoteInPartiQL: true) + let table = try getTable(escapeSingleQuoteInPartiQL: true) let expression = try table.getDeleteExpression(tableName: tableName, existingItem: databaseItemA) @@ -620,7 +625,7 @@ struct TypedTTLDatabaseItemRowWithItemVersionProtocolTests { sortKey: "sortKey") let databaseItemA = StandardTypedDatabaseItem.newItem(withKey: compositeKey, andValue: payloadA) - let table = InMemoryDynamoDBCompositePrimaryKeyTable() + let table = try getTable() let expression = try table.getDeleteExpression(tableName: tableName, existingItem: databaseItemA)