Skip to content

Latest commit

 

History

History
48 lines (42 loc) · 5.6 KB

cheat-sheet.md

File metadata and controls

48 lines (42 loc) · 5.6 KB
id title
cheat-sheet
High Level API Cheat Sheet

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.id.partitionKey === id).execute
Query with paging (people, lastEvaluatedKey) <- querySome[Person]("personTable", limit = 5).whereKey(Person.id.partitionKey === "1").execute
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 tuple <- (get("personTable")(Person.id.partitionKey === "1") zip get("employeeTable")(Employee.id.partitionKey === "2")).transaction.execute Note transactions can span different tables.
TransactWriteItems _ <- (put("personTable", Person(1, "John", 2020)) zip put("employeeTable", Person(2, "Smith", 2024))).transaction.execute Note transactions can span different tables.