From acc5a028c9e4e477a6aa9a1eb2aa13e35ced0fe7 Mon Sep 17 00:00:00 2001 From: Avinder Bahra Date: Thu, 24 Oct 2024 12:52:34 +0100 Subject: [PATCH] improve examples --- .../zio/dynamodb/TypeSafeApiAlternateModeling.scala | 2 +- .../zio/dynamodb/TypeSafeApiSingleTableSpec.scala | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiAlternateModeling.scala b/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiAlternateModeling.scala index 702543d0..6cb11571 100644 --- a/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiAlternateModeling.scala +++ b/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiAlternateModeling.scala @@ -66,7 +66,7 @@ object TypeSafeApiAlternateModeling extends DynamoDBLocalSpec { object Contract { implicit val schema: Schema.CaseClass5[String, Option[String], Option[String], Boolean, ContractBody, Contract] = DeriveSchema.gen[Contract] - val (id, identityId, accountId, isTest, body) = ProjectionExpression.accessors[Contract] + val (id, alternateId, accountId, isTest, body) = ProjectionExpression.accessors[Contract] } } diff --git a/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiSingleTableSpec.scala b/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiSingleTableSpec.scala index 0f5efa3e..48e50ee8 100644 --- a/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiSingleTableSpec.scala +++ b/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiSingleTableSpec.scala @@ -11,13 +11,14 @@ import java.time.Instant import zio.schema.annotation.discriminatorName import zio.ZIO -/** Demonstrates how to implement the single table pattern (also known as the adjacency lists pattern) using the type-safe API. - * see https://www.alexdebrie.com/posts/dynamodb-single-table/ - * see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html - */ +/** + * Demonstrates how to implement the single table pattern (also known as the adjacency lists pattern) using the type-safe API + * using sum and product types. + * see https://www.alexdebrie.com/posts/dynamodb-single-table/ + * see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html + */ object TypeSafeApiSingleTableSpec extends DynamoDBLocalSpec { - @discriminatorName("userBodyType") sealed trait UserBody object UserBody { @@ -45,7 +46,7 @@ object TypeSafeApiSingleTableSpec extends DynamoDBLocalSpec { val (id, selector, userBody) = ProjectionExpression.accessors[User] // smart constructors manage the id and sort keys - + def makeProfile(username: String, fullName: String, email: String, createdAt: Instant): User = User(s"USER#$username", s"Profile#$username", UserBody.Profile(username, fullName, email, createdAt))