Swiftpack.co - nikola-mladenovic/AwsSwiftDynamoDBsdk as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by nikola-mladenovic.
nikola-mladenovic/AwsSwiftDynamoDBsdk 0.4.0
Swift library providing easy access to common DynamoDB operations
⭐️ 6
🕓 3 years ago
.package(url: "https://github.com/nikola-mladenovic/AwsSwiftDynamoDBsdk.git", from: "0.4.0")

AwsDynamoDB - Swift

AwsDynamoDB is a Swift library that enables you to use Amazon DynamoDB with Swift. More details on this are available from the AWS DynamoDB docmentation.

Swift 5.2 Platforms iOS | macOS | watchOS | tvOS | Linux SPM compatible

This package builds with Swift Package Manager. Ensure you have installed and activated the latest Swift 4.2 tool chain.

Quick Start

To use AwsSns, modify the Package.swift file and add following dependency:

.package(url: "https://github.com/nikola-mladenovic/AwsSwiftDynamoDBsdk", from: "0.4.0")

Then import the AwsDynamoDB library into the swift source code:

import AwsDynamoDB

Usage

The current release supports following functionalities: Get Item, Put Item, Delete Item and Query. Library uses Codable to encode and decode items sent and recieved from DynamoDB.

To use library first initialize the AwsDynamoDB instance with your credentials and host. After that initialize AwsDynamoDBTable instance:

let dynamoDb = AwsDynamoDB(host: "https://dynamodb.us-west-2.amazonaws.com", accessKeyId: "OPKASPJPOAS23IOJS", secretAccessKey: "232(I(%$jnasoijaoiwj2919109233")
let testTable = dynamoDb.table(name: "test")

To get item from DynamoDB use the getItem method of the AwsDynamoDBTable instance:

testTable.getItem(key: (field: "id", value: "012345"), completion: { (success, item, error) in
    // Do some work
    ...
})

To put item from DynamoDB use the putItem method of the AwsDynamoDBTable instance:

struct Person: Codable {
    let id: String
    let name: String?
}

let person = Person(id: "012345", name: "Bill")

testTable.put(item: person, completion: { (success, error) in
    // Do some work
    ...
})

To delete item from DynamoDB use the deleteItem method of the AwsDynamoDBTable instance:

testTable.deleteItem(key: (field: "id", value: "012345"), completion: { (success, error) in
    // Do some work
    ...
})

To update item on DynamoDB use the update method of the AwsDynamoDBTable instance:

testTable.update(key: (field: "id", value: "012345"),
                 expressionAttributeValues: [":newBool" : true, ":incVal" : 3],
                 updateExpression: "SET bool=:newBool, num = num + :incVal",
                 completion: { (success, error) in
    // Do some work
    ...
})

To query items in DynamoDB use the query method of the AwsDynamoDBTable instance:

testTable.query(keyConditionExpression: "id = :ident", expressionAttributeValues: [":ident" : "012345"]) { (success, items, error) in
    // Do some work
    ...
}

To scan items in DynamoDB use the scan method of the AwsDynamoDBTable instance:

testTable.scan(expressionAttributeValues: [":ident" : "Test"], filterExpression: "id = :ident", limit: 1) { (success, items, error) in
// Do some work
...
}

GitHub

link
Stars: 6
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Swift 5.2 support
3 years ago

0.4.0

Released on 2019-07-08.

Added

  • Swift 5.2 support.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics