Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
Amend dynamodb/README with documentation for #329 and #337 (#345)
Browse files Browse the repository at this point in the history
(and fix a small typo)
  • Loading branch information
obecker authored Jan 5, 2024
1 parent a86405c commit f34e6b6
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion amazon/dynamodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,33 @@ val boolean: Result<Boolean, LensFailure> = attrBool.asResult()(item)

It is also possible to `map()` lenses to provide marshalling into your own types.

#### Null handling and sparse indexes

The default mapping for null values of manually mapped optional attributes in DynamoDB will assign them to an explicit
null attribute:
```kotlin
val attrS = Attribute.string().optional("optS")
val item = Item(attrS of null)

// item now contains "optS": { "NULL": true }
```

When utilizing an optional attribute as a key in a secondary index (creating a sparse index), the attribute must be
absent rather than null. To achieve this, set `ignoreNull` to true in the attribute definition.
```kotlin
val attrS = Attribute.string().optional("optS", ignoreNull = true)
```

When incorporating this attribute into the secondary index schema, it is necessary to convert it into a mandatory
(non-optional) attribute.
```kotlin
// attrS is of type Attribute<String?>

attrS.asRequired() // will be of type Attribute<String>
```

Note: null properties of automapped objects (using `autoDynamoLens()`) will be ignored by default.

### DynamoDB Table Repository

A simplified API for mapping documents to and from a single table with `get`, `put`, `scan`, `query`, etc.
Expand Down Expand Up @@ -166,7 +193,7 @@ client.putItem(

// lookup an item from the database
val item = client.getItem(table, key = mapOf(attrS to "hello")).valueOrNull()!!.item!!
val str: String? = attrS[item]
val str: String? = attrS(item)

// all operations return a Result monad of the API type
val deleteResult: Result<TableDescriptionResponse, RemoteFailure> = client.deleteTable(table)
Expand Down

0 comments on commit f34e6b6

Please sign in to comment.