Skip to content

Latest commit

 

History

History
44 lines (38 loc) · 5.35 KB

cheat-sheet.md

File metadata and controls

44 lines (38 loc) · 5.35 KB

High Level API Cheat Sheet

Note this guide assumes the reader has some basic knowledge of AWS DynamoDB API.

Assuming the below model

final case class Person(id: String, name: String, year: Int)
object Person {
  implicit val schema: Schema.CaseClass3[String, String, Int, Person] = DeriveSchema.gen[Person]
  val (id, name, year) = ProjectionExpression.accessors[Person]
}

For more detailed working examples please see the High Level API integration tests crud, mapping, scan and query, streaming

AWS ZIO DynamoDB
GetItem person <- get("personTable")(Person.id.partitionKey === "1").execute
UpdateItem _ <- update("personTable")(Person.id.partitionKey === "1")(Person.name.set("Foo")).execute
PutItem _ <- put("personTable", Person("42", "John", 2020)).execute
DeleteItem _ <- deleteFrom("personTable")(Person.id.partitionKey === "1").execute
Projection Expressions Person.id, Person.name, Person.year
Condition Expressions <DynamoDBQuery>.where(Person.id === "1")
Filter Expressions apply to Scan and Query <DynamoDBQuery>.filter(Person.year > 2020)
Update Expressions update("personTable")(Person.id.partitionKey === "1")(Person.name.set("John") + Person.year.add(1))
Primary Keys Person.id.partitionKey === "1" or Person.id.partitionKey === "1" && Person.year.sortKey === 2020 if table has both partition and sort keys
Key Condition Expressions <query>.whereKey(Person.id.partitionKey === "1" && Person.year.sortKey > 2020)
Expression Attribute Names Managed automatically!
Expression Attribute Values Managed automatically!
Scan stream <- scanAll[Person]("personTable").execute
Scan with parallel processing stream <- scanAll[Person]("personTable").parallel(42).execute
Scan with paging (people, lastEvaluatedKey) <- scanSome[Person]("personTable", limit = 5).startKey(oldLastEvaluatedKey).execute
Query stream <- queryAll[Person]("personTable").whereKey(Person.name.contains("mi")).execute
Query with paging (people, lastEvaluatedKey) <- querySome[Person]("personTable", limit = 5).whereKey(Person.name.contains("mi"))
BatchGetItem people <- DynamoDBQuery.forEach(listOfIds)(id => DynamoDBQuery.get[Person]("personTable")(Person.id.partitionKey === id)).execute
BatchWriteItem _ <- DynamoDBQuery.forEach(people)(p => put("personTable", p)).execute
TransactGetItems val getJohn = get("personTable")(Person.id.partitionKey === "1")
val getSmith = get("personTable")(Person.id.partitionKey === "2")
tuple <- (getJohn zip getSmith).transaction.execute
TransactWriteItems val putJohn = put("personTable", Person("1", "John", 2020))
val putSmith = put("personTable", Person("2", "Smith", 2024))
_ <- (putJohn zip putSmith).transaction.execute