Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation #58

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
retention-days: 7

test-documentation:
if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/')
#if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/')
needs: build-documentation
runs-on: ubuntu-latest

Expand All @@ -62,7 +62,7 @@ jobs:
instance: ${{ env.INSTANCE }}

deploy-documentation:
# if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/')
#if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/')
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
1 change: 1 addition & 0 deletions doc/Writerside/akm.tree
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
start-page="Default-topic.md">

<toc-element topic="Default-topic.md"/>
<toc-element topic="DynamoDB.md"/>
<toc-element topic="S3.md"/>
</instance-profile>
1 change: 1 addition & 0 deletions doc/Writerside/topics/Default-topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ If you want to re-add it for your experiments, click + to create a new topic, ch

<list type="none">
<li><a href="S3.md">S3</a></li>
<li><a href="DynamoDB.md">DynamoDB</a></li>
</list>
172 changes: 172 additions & 0 deletions doc/Writerside/topics/DynamoDB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# DynamoDB

<show-structure for="chapter,procedure" depth="4"/>

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Kotlin with DynamoDB.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context.

## Configuration

<list type="decimal">
<li>Add dependency in module shared/build.gradle.kts
<code-block lang="kotlin">
val commonMain by getting {
dependencies {
implementation("io.github.estivensh4:aws-dynamo:$lastVersion")
}
}
</code-block>
</li>
<li>Add pod in module shared/build.gradle.kts
<code-block lang="kotlin">
cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
version = "1.0"
ios.deploymentTarget = "14.1"
framework {
baseName = "shared"
}
pod("AWSDynamoDB", "~> 2.33.4") // add this line
}
</code-block>
</li>
<li>Add pod in iosApp/Podfile
<code-block>
target 'iosApp' do
use_frameworks!
platform :ios, '14.1'
pod 'shared', :path => '../shared'
pod 'AWSDynamoDB', '~> 2.33.4' # add this line
end
</code-block>
</li>
</list>

## Examples
### Configure client
<code-block lang="kotlin">
val builder = AWSBuilder()
.accessKey("YOUR_ACCESS_KEY")
.secretKey("YOUR_SECRET_KEY")
client = builder.buildDynamo()
</code-block>

### Create table
```Kotlin
val request = CreateTableRequest(
tableName = tableName,
keySchemaList = listOf(
KeySchemaElement(
attributeName = "year",
keyType = KeyType.HASH
),
KeySchemaElement(
attributeName = "title",
keyType = KeyType.RANGE
)
),
attributeDefinitions = listOf(
AttributeDefinition(
attributeName = "year",
attributeType = ScalarAttributeType.N
),
AttributeDefinition(
attributeName = "title",
attributeType = ScalarAttributeType.S
)
)
)

val result = client.createTable(request)
```

### Put item
<code-block lang="kotlin">
val result = client.putItem(
tableName = tableName,
items = mapOf(
"year" to AttributeValue.Builder().withN("6").build(),
"title" to AttributeValue.Builder().withS("Title").build(),
"customerId" to AttributeValue.Builder().withS("1").build(),
"emailAddress" to AttributeValue.Builder().withS("[email protected]").build(),
"firstName" to AttributeValue.Builder().withS("Test").build(),
"lastName" to AttributeValue.Builder().withS("Test").build()
)
)
</code-block>

### Get all tables
<code-block lang="kotlin">
val result = client.getAllTables()
</code-block>

### Get item
<code-block lang="kotlin">
val result = client.getItem(
tableName = tableName,
items = mapOf(
"year" to AttributeValue.Builder().withN(n).build(),
"title" to AttributeValue.Builder().withS(title).build(),
)
)
</code-block>

### Delete item
<code-block lang="kotlin">
val result = client.deleteItem(
tableName = tableName,
items = mapOf(
"year" to AttributeValue.Builder().withN(n).build(),
"title" to AttributeValue.Builder().withS(title).build(),
)
)
</code-block>

### Query item
<code-block lang="kotlin">
val desiredYear = 10
val result = client.query(
QueryRequest.Builder()
.withTableName(tableName)
.withKeyConditionExpression("#yr = :yearValue")
.withExpressionAttributeNames(mapOf("#yr" to "year"))
.withExpressionAttributeValues(
mapOf(
":yearValue" to AttributeValue.Builder().withN(desiredYear.toString()).build()
)
)
.build()
)
</code-block>

### Scan item
<code-block lang="kotlin">
val result = client.scan(
ScanRequest.Builder()
.withTableName(tableName)
.build()
)
</code-block>

### Update item
<code-block lang="kotlin">
val year = 5
val title = "Title"
val result = client.updateItem(
tableName = tableName,
keys = mapOf(
"year" to AttributeValue.Builder().withN(year.toString()).build(),
"title" to AttributeValue.Builder().withS(title).build()
),
attributeValueUpdate = mapOf(
"customerId" to AttributeValueUpdate.Builder()
.withValue(AttributeValue.Builder().withS("Mario").build()).build()
)
)
</code-block>
2 changes: 1 addition & 1 deletion doc/Writerside/writerside.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<images dir="images" web-path="aws-kmp"/>
<categories src="c.list"/>
<vars src="v.list"/>
<instance src="akm.tree" keymaps-mode="provided" version="v0.5.6"/>
<instance src="akm.tree" keymaps-mode="provided" version="v0.6.0"/>
</ihp>
Loading