Skip to content

Commit a3118fc

Browse files
Swift 5.2
1 parent 4e4cdf9 commit a3118fc

File tree

6 files changed

+43
-43
lines changed

6 files changed

+43
-43
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ os:
33
- osx
44

55
language: generic
6-
osx_image: xcode10
6+
osx_image: xcode11.3
77
sudo: required
8-
dist: trusty
8+
dist: buster
99

1010
env:
11-
- SWIFT_VERSION=4.2
11+
- SWIFT_VERSION=5.2.4
1212

1313
install:
14-
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
14+
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
1515

1616
script:
1717
- swift test

AwsDynamoDBsdk.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
Pod::Spec.new do |s|
22

33
s.name = "AwsDynamoDBsdk"
4-
s.version = "0.2.0"
4+
s.version = "0.4.0"
55
s.summary = "Swift library providing easy access to common DynamoDB operations"
66
s.homepage = "https://github.com/nikola-mladenovic/AwsSwiftDynamoDBsdk"
77
s.license = { :type => "Apache License, Version 2.0", :file => "LICENSE" }
88
s.author = { "Nikola Mladenovic" => "[email protected]" }
99
s.source = { :git => "https://github.com/nikola-mladenovic/AwsSwiftDynamoDBsdk.git", :tag => s.version.to_s }
1010
s.source_files = 'Sources/AwsDynamoDB/*.swift'
11-
s.swift_version = "4.2"
12-
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.1' }
11+
s.swift_version = "5.2"
12+
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '5.2' }
1313

1414
s.ios.deployment_target = '10.0'
1515
s.osx.deployment_target = '10.10'
1616
s.tvos.deployment_target = '9.0'
1717
s.watchos.deployment_target = '2.2'
1818

19-
s.dependency 'AwsSign', '~> 0.3'
19+
s.dependency 'AwsSign', '~> 0.4'
2020

2121
end

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.2
22

33
import PackageDescription
44

55
let package = Package(
66
name: "AwsDynamoDB",
77
products: [.library(name: "AwsDynamoDB", targets: ["AwsDynamoDB"])],
8-
dependencies: [.package(url: "https://github.com/nikola-mladenovic/AwsSwiftSign.git", from: "0.3.0")],
8+
dependencies: [.package(name: "AwsSign", url: "https://github.com/nikola-mladenovic/AwsSwiftSign.git", from: "0.4.0")],
99
targets: [.target(name: "AwsDynamoDB", dependencies: ["AwsSign"]),
1010
.testTarget(name: "AwsDynamoDBTests", dependencies: ["AwsDynamoDB"])],
1111
swiftLanguageVersions: [.v5]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ AwsDynamoDB is a Swift library that enables you to use Amazon DynamoDB with Swi
77
<img src="https://travis-ci.org/nikola-mladenovic/AwsSwiftDynamoDBsdk.svg?branch=master">
88
</a>
99
<a href="https://developer.apple.com/swift/" target="_blank">
10-
<img src="https://img.shields.io/badge/Swift-5.1-orange.svg?style=flat" alt="Swift 5.1">
10+
<img src="https://img.shields.io/badge/Swift-5.2-orange.svg?style=flat" alt="Swift 5.2">
1111
</a>
1212
<a href="https://developer.apple.com/swift/" target="_blank">
1313
<img src="https://img.shields.io/badge/Platforms-iOS%20%7C%20macOS%20%7C%20watchOS%20%7C%20tvOS%20%7C%20Linux-4E4E4E.svg?colorA=EF5138" alt="Platforms iOS | macOS | watchOS | tvOS | Linux">
@@ -24,7 +24,7 @@ This package builds with Swift Package Manager. Ensure you have installed and ac
2424
To use AwsSns, modify the Package.swift file and add following dependency:
2525

2626
``` swift
27-
.package(url: "https://github.com/nikola-mladenovic/AwsSwiftDynamoDBsdk", from: "0.3.0")
27+
.package(url: "https://github.com/nikola-mladenovic/AwsSwiftDynamoDBsdk", from: "0.4.0")
2828
```
2929

3030
Then import the `AwsDynamoDB` library into the swift source code:

Sources/AwsDynamoDB/AwsDynamoDB.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ public struct AwsDynamoDBTable {
7777
/// Method used for fetching items from table.
7878
///
7979
/// - Parameters:
80-
/// - key: Tuple that represents primary key, e.g `(field: "id", "012345")`
80+
/// - keyParams: Dictionary that represents primary key, or primary and sort key, e.g `["id": "012345"]`, or `["id": "1", "name": "doe"]`
8181
/// - fetchAttributes: Array that represents attributes that should be returned from item. Defaults to empty array.
8282
/// - consistentRead: If your application requires a strongly consistent read, set this parameter to 'true'. Defaults to `false`.
8383
/// - completion: Completion closure that will be called when request has completed.
8484
/// - success: Bool value that will be `true` if request has succeeded, otherwise false.
8585
/// - item: Item returned from DynamoDB or `nil` if request has failed. Item must conform to `Decodable` protocol.
8686
/// - error: Error if request has failed or `nil` if request has succeeded.
87-
public func getItem<T: Decodable>(key: (field: String, value: Any), fetchAttributes: [String] = [], consistentRead: Bool = false, completion: @escaping (Bool, T?, Error?) -> Void) {
87+
public func getItem<T: Decodable>(keyParams: [String: Any], fetchAttributes: [String] = [], consistentRead: Bool = false, completion: @escaping (Bool, T?, Error?) -> Void) {
8888
var params: [String : Any] = [ "TableName" : name,
8989
"ConsistentRead" : consistentRead,
90-
"Key" : toAwsJson(from: [key.field : key.value]) ]
90+
"Key" : toAwsJson(from: keyParams) ]
9191
if fetchAttributes.count > 0 {
9292
params["ProjectionExpression"] = fetchAttributes.joined(separator: ",")
9393
}
@@ -119,13 +119,13 @@ public struct AwsDynamoDBTable {
119119
/// Method used for deleteting items from table.
120120
///
121121
/// - Parameters:
122-
/// - key: Tuple that represents primary key, e.g `(field: "id", "012345")`
122+
/// - keyParams: Dictionary that represents primary key, or primary and sort key, e.g `["id": "012345"]`, or `["id": "1", "name": "doe"]`
123123
/// - completion: Completion closure that will be called when request has completed.
124124
/// - success: Bool value that will be `true` if request has succeeded, otherwise false.
125125
/// - error: Error if request has failed or `nil` if request has succeeded.
126-
public func deleteItem(key: (field :String, value: Any), completion: @escaping (Bool, Error?) -> Void) {
126+
public func deleteItem(keyParams: [String: Any], completion: @escaping (Bool, Error?) -> Void) {
127127
let params: [String : Any] = [ "TableName" : name,
128-
"Key" : toAwsJson(from: [key.field : key.value]) ]
128+
"Key" : toAwsJson(from: keyParams) ]
129129

130130
let request: URLRequest
131131
do {
@@ -166,17 +166,17 @@ public struct AwsDynamoDBTable {
166166
/// Methods used for updating the items in table.
167167
///
168168
/// - Parameters:
169-
/// - key: Tuple that represents primary key, e.g `(field: "id", "012345")`
169+
/// - keyParams: Dictionary that represents primary key, or primary and sort key, e.g `["id": "012345"]`, or `["id": "1", "name": "doe"]`
170170
/// - conditionExpression: A condition that must be satisfied in order for a conditional update to succeed.
171171
/// - expressionAttributeNames: One or more substitution tokens for attribute names in an expression.
172172
/// - expressionAttributeValues: One or more values that can be substituted in an expression.
173173
/// - updateExpression: An expression that defines one or more attributes to be updated, the action to be performed on them, and new value(s) for them. For more information, see [Amazon DynamoDB Update Expressions Documentation.](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html)
174174
/// - completion: Completion closure that will be called when request has completed.
175175
/// - success: Bool value that will be `true` if request has succeeded, otherwise false.
176176
/// - error: Error if request has failed or `nil` if request has succeeded.
177-
public func update(key: (field :String, value: Any), conditionExpression: String? = nil, expressionAttributeNames: [String : String]? = nil, expressionAttributeValues: [String : Any?]? = nil, updateExpression: String? = nil, completion: @escaping (Bool, Error?) -> Void) {
177+
public func update(keyParams: [String: Any], conditionExpression: String? = nil, expressionAttributeNames: [String : String]? = nil, expressionAttributeValues: [String : Any?]? = nil, updateExpression: String? = nil, completion: @escaping (Bool, Error?) -> Void) {
178178
var params: [String : Any] = [ "TableName" : name,
179-
"Key" : toAwsJson(from: [key.field : key.value]) ]
179+
"Key" : toAwsJson(from: keyParams) ]
180180
if let conditionExpression = conditionExpression {
181181
params["ConditionExpression"] = conditionExpression
182182
}
@@ -212,35 +212,35 @@ public struct AwsDynamoDBTable {
212212
/// - expressionAttributeNames: Substitution tokens for attribute names in an key condition expression.
213213
/// - expressionAttributeValues: Values that can be substituted in an key condition expression.
214214
/// - fetchAttributes: Array that represents attributes that should be returned from item. Defaults to empty array.
215-
/// - startKey: Tuple that represents primary key, e.g `(field: "id", "012345")`. If start key is specified, query will start from item with that key. Defaults to `nil`.
215+
/// - startKeyParams: Dictionary that represents primary key, or primary and sort key, e.g `["id": "012345"]`, or `["id": "1", "name": "doe"]`. If start key is specified, query will start from item with that key. Defaults to `nil`.
216216
/// - filterExpression: A string that contains conditions that DynamoDB applies after the query operation, but before the items are returned to you. Items that do not satisfy criteria are not returned.
217217
/// - limit: Limit number of items returned by query. Defaults to nil.
218218
/// - consistentRead: If your application requires a strongly consistent read, set this parameter to 'true'. Defaults to `false`.
219219
/// - completion: Completion closure that will be called when request has completed.
220220
/// - success: Bool value that will be `true` if request has succeeded, otherwise false.
221221
/// - items: Items returned from DynamoDB or `nil` if request has failed. Items must conform to `Codable` protocol.
222222
/// - error: Error if request has failed or `nil` if request has succeeded.
223-
public func query<T: Decodable>(indexName: String? = nil, keyConditionExpression: String, expressionAttributeNames: [String : String]? = nil, expressionAttributeValues: [String : Any]? = nil, fetchAttributes: [String] = [], startKey: (field :String, value: Any)? = nil, filterExpression: String? = nil, limit: Int? = nil, consistentRead: Bool = false, completion: @escaping (Bool, [T]?, Error?) -> Void) {
223+
public func query<T: Decodable>(indexName: String? = nil, keyConditionExpression: String, expressionAttributeNames: [String : String]? = nil, expressionAttributeValues: [String : Any]? = nil, fetchAttributes: [String] = [], startKeyParams: [String: Any]? = nil, filterExpression: String? = nil, limit: Int? = nil, consistentRead: Bool = false, completion: @escaping (Bool, [T]?, Error?) -> Void) {
224224
var params: [String : Any] = [ "TableName" : name,
225225
"KeyConditionExpression" : keyConditionExpression,
226226
"ConsistentRead" : consistentRead ]
227227
if let indexName = indexName {
228228
params["IndexName"] = indexName
229229
}
230-
if let expressionAttributeNames = expressionAttributeNames{
230+
if let expressionAttributeNames = expressionAttributeNames {
231231
params["ExpressionAttributeNames"] = expressionAttributeNames
232232
params["Select"] = "SPECIFIC_ATTRIBUTES"
233233
}
234-
if let expressionAttributeValues = expressionAttributeValues{
234+
if let expressionAttributeValues = expressionAttributeValues {
235235
params["ExpressionAttributeValues"] = toAwsJson(from: expressionAttributeValues)
236236
}
237-
if let startKey = startKey{
238-
params["ExclusiveStartKey"] = toAwsJson(from: [startKey.field : startKey.value])
237+
if let startKeyParams = startKeyParams {
238+
params["ExclusiveStartKey"] = toAwsJson(from: startKeyParams)
239239
}
240-
if let filterExpression = filterExpression{
240+
if let filterExpression = filterExpression {
241241
params["FilterExpression"] = filterExpression
242242
}
243-
if let limit = limit{
243+
if let limit = limit {
244244
params["Limit"] = limit
245245
}
246246
if fetchAttributes.count > 0 {
@@ -280,34 +280,34 @@ public struct AwsDynamoDBTable {
280280
/// - expressionAttributeNames: Substitution tokens for attribute names in an key condition expression.
281281
/// - expressionAttributeValues: Values that can be substituted in an key condition expression.
282282
/// - fetchAttributes: Array that represents attributes that should be returned from item. Defaults to empty array.
283-
/// - startKey: Tuple that represents key, e.g `(field: "id", "012345")`. If start key is specified, scan will start from item with that key. Defaults to `nil`.
283+
/// - startKeyParams: Dictionary that represents primary key, or primary and sort key, e.g `["id": "012345"]`, or `["id": "1", "name": "doe"]`. If start key is specified, scan will start from item with that key. Defaults to `nil`.
284284
/// - filterExpression: A string that contains conditions that DynamoDB applies after the query operation, but before the items are returned to you. Items that do not satisfy criteria are not returned.
285285
/// - limit: Limit number of items returned by query. Defaults to nil.
286286
/// - consistentRead: If your application requires a strongly consistent read, set this parameter to 'true'. Defaults to `false`.
287287
/// - completion: Completion closure that will be called when request has completed.
288288
/// - success: Bool value that will be `true` if request has succeeded, otherwise false.
289289
/// - items: Items returned from DynamoDB or `nil` if request has failed. Items must conform to `Codable` protocol.
290290
/// - error: Error if request has failed or `nil` if request has succeeded.
291-
public func scan<T: Decodable>(indexName: String? = nil, expressionAttributeNames: [String : String]? = nil, expressionAttributeValues: [String : Any]? = nil, fetchAttributes: [String] = [], startKey: (field :String, value: Any)? = nil, filterExpression: String? = nil, limit: Int? = nil, consistentRead: Bool = false, completion: @escaping (Bool, [T]?, Error?) -> Void) {
291+
public func scan<T: Decodable>(indexName: String? = nil, expressionAttributeNames: [String : String]? = nil, expressionAttributeValues: [String : Any]? = nil, fetchAttributes: [String] = [], startKeyParams: [String: Any]? = nil, filterExpression: String? = nil, limit: Int? = nil, consistentRead: Bool = false, completion: @escaping (Bool, [T]?, Error?) -> Void) {
292292
var params: [String : Any] = [ "TableName" : name,
293293
"ConsistentRead" : consistentRead ]
294294
if let indexName = indexName {
295295
params["IndexName"] = indexName
296296
}
297-
if let expressionAttributeNames = expressionAttributeNames{
297+
if let expressionAttributeNames = expressionAttributeNames {
298298
params["ExpressionAttributeNames"] = expressionAttributeNames
299299
params["Select"] = "SPECIFIC_ATTRIBUTES"
300300
}
301-
if let expressionAttributeValues = expressionAttributeValues{
301+
if let expressionAttributeValues = expressionAttributeValues {
302302
params["ExpressionAttributeValues"] = toAwsJson(from: expressionAttributeValues)
303303
}
304-
if let startKey = startKey{
305-
params["ExclusiveStartKey"] = toAwsJson(from: [startKey.field : startKey.value])
304+
if let startKeyParams = startKeyParams {
305+
params["ExclusiveStartKey"] = toAwsJson(from: startKeyParams)
306306
}
307-
if let filterExpression = filterExpression{
307+
if let filterExpression = filterExpression {
308308
params["FilterExpression"] = filterExpression
309309
}
310-
if let limit = limit{
310+
if let limit = limit {
311311
params["Limit"] = limit
312312
}
313313
if fetchAttributes.count > 0 {

Tests/AwsDynamoDBTests/AwsDynamoDBTest.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AwsDynamoDBTest: XCTestCase {
2323

2424
func testGetItem() {
2525
let getItemExpectation = expectation(description: "getItemAsyncCall")
26-
testTable?.getItem(key: (field: "id", value: "Test"), completion: { (success, item: Item?, error) in
26+
testTable?.getItem(keyParams: ["id": "Test", "name": "Marek Sokol"], completion: { (success, item: Item?, error) in
2727
XCTAssert(success, "Request failed")
2828
XCTAssertNil(error, "Error should be nil")
2929
XCTAssertNotNil(item, "Item should not be nil")
@@ -57,7 +57,7 @@ class AwsDynamoDBTest: XCTestCase {
5757

5858
testTable?.put(item: item, completion: { (rSuccess, rError) in
5959
if rSuccess {
60-
self.testTable?.deleteItem(key: (field: "id", value: "Test2"), completion: { (rSuccess, rError) in
60+
self.testTable?.deleteItem(keyParams: ["id": item.id, "name": item.name], completion: { (rSuccess, rError) in
6161
error = rError
6262
success = rSuccess
6363
deleteItemExpectation.fulfill()
@@ -76,11 +76,11 @@ class AwsDynamoDBTest: XCTestCase {
7676
let item = Item(id: "TestUpdateItem", name: "Update Item", bool: false, num: 2)
7777
let testUpdateItemExpectation = expectation(description: "testUpdateItem")
7878

79-
let key: (String, Any) = (field: "id", value: "TestUpdateItem")
80-
testTable?.deleteItem(key: key, completion: { _, _ in
79+
let keyParams = ["id": item.id, "name": item.name]
80+
testTable?.deleteItem(keyParams: keyParams, completion: { _, _ in
8181
self.testTable?.put(item: item, completion: { _, _ in
82-
self.testTable?.update(key: key, expressionAttributeValues: [":newBool" : true, ":incVal" : 3], updateExpression: "SET bool=:newBool, num = num + :incVal", completion: { success, error in
83-
self.testTable?.getItem(key: key, completion: { (_, item: Item?, _) in
82+
self.testTable?.update(keyParams: keyParams, expressionAttributeValues: [":newBool" : true, ":incVal" : 3], updateExpression: "SET bool=:newBool, num = num + :incVal", completion: { success, error in
83+
self.testTable?.getItem(keyParams: keyParams, completion: { (_, item: Item?, _) in
8484
XCTAssert(success, "Request failed")
8585
XCTAssertNil(error, "Error should be nil")
8686
XCTAssert(item?.bool == true, "Bool not updated")

0 commit comments

Comments
 (0)