diff --git a/dynamodb/src/it/scala/zio/dynamodb/LiveSpec.scala b/dynamodb/src/it/scala/zio/dynamodb/LiveSpec.scala index d0eb54432..1d6176212 100644 --- a/dynamodb/src/it/scala/zio/dynamodb/LiveSpec.scala +++ b/dynamodb/src/it/scala/zio/dynamodb/LiveSpec.scala @@ -158,7 +158,7 @@ object LiveSpec extends ZIOSpecDefault { } } - def withKeywordsTable( + def withPkKeywordsTable( f: String => ZIO[DynamoDBExecutor, Throwable, TestResult] ) = ZIO.scoped { @@ -198,65 +198,59 @@ object LiveSpec extends ZIOSpecDefault { val (id, num, ttl) = ProjectionExpression.accessors[ExpressionAttrNames] } - final case class ExpressionAttrNames2(and: String, source: String, ttl: Option[Long]) - object ExpressionAttrNames2 { - implicit val schema: Schema.CaseClass3[String, String, Option[Long], ExpressionAttrNames2] = - DeriveSchema.gen[ExpressionAttrNames2] - val (and, source, ttl) = ProjectionExpression.accessors[ExpressionAttrNames2] + final case class ExpressionAttrNamesPkKeywords(and: String, source: String, ttl: Option[Long]) + object ExpressionAttrNamesPkKeywords { + implicit val schema: Schema.CaseClass3[String, String, Option[Long], ExpressionAttrNamesPkKeywords] = + DeriveSchema.gen[ExpressionAttrNamesPkKeywords] + val (and, source, ttl) = ProjectionExpression.accessors[ExpressionAttrNamesPkKeywords] } - val debugSuite = suite("debug")( - test("queryAll should handle keywords in primary key names using high level API") { - withKeywordsTable { tableName => - val query = DynamoDBQuery - .queryAll[ExpressionAttrNames2](tableName) - .whereKey(ExpressionAttrNames2.and === "and1" && ExpressionAttrNames2.source === "source1") - .filter(ExpressionAttrNames2.ttl.notExists) - query.execute.flatMap(_.runDrain).exit.map { result => - assert(result)(succeeds(isUnit)) - } - } - }, - test("queryAll should handle keywords in primary key names using low level API") { - withKeywordsTable { tableName => - val query = DynamoDBQuery - .queryAll[ExpressionAttrNames2](tableName) - .whereKey(partitionKey("and") === "and1" && sortKey("source") === "source1") - .filter(ExpressionAttrNames2.ttl.notExists) - query.execute.flatMap(_.runDrain).exit.map { result => - assert(result)(succeeds(isUnit)) - } - } - } - ) - .provideSomeLayerShared[TestEnvironment]( - testLayer.orDie - ) @@ nondeterministic - val mainSuite: Spec[TestEnvironment, Any] = suite("live test")( suite("key words in Key Condition Expressions")( - test("queryAll should handle keywords in primary key name using high level API") { - withKeywordsTable { tableName => + test("queryAll should handle keywords in primary key names using high level API") { + withPkKeywordsTable { tableName => val query = DynamoDBQuery - .queryAll[ExpressionAttrNames2](tableName) - .whereKey(ExpressionAttrNames2.and === "and1" && ExpressionAttrNames2.source === "source1") - .filter(ExpressionAttrNames2.ttl.notExists) + .queryAll[ExpressionAttrNamesPkKeywords](tableName) + .whereKey(ExpressionAttrNamesPkKeywords.and === "and1" && ExpressionAttrNamesPkKeywords.source === "source1") + .filter(ExpressionAttrNamesPkKeywords.ttl.notExists) query.execute.flatMap(_.runDrain).exit.map { result => assert(result)(succeeds(isUnit)) } } }, test("queryAll should handle keywords in primary key name using low level API") { - withKeywordsTable { tableName => + withPkKeywordsTable { tableName => val query = DynamoDBQuery - .queryAll[ExpressionAttrNames2](tableName) + .queryAll[ExpressionAttrNamesPkKeywords](tableName) .whereKey(partitionKey("and") === "and1" && sortKey("source") === "source1") - .filter(ExpressionAttrNames2.ttl.notExists) + .filter(ExpressionAttrNamesPkKeywords.ttl.notExists) query.execute.flatMap(_.runDrain).exit.map { result => assert(result)(succeeds(isUnit)) } } + }, + test("querySome should handle keywords in primary key name using high level API") { + withPkKeywordsTable { tableName => + val query = DynamoDBQuery + .querySome[ExpressionAttrNamesPkKeywords](tableName, 1) + .whereKey(ExpressionAttrNamesPkKeywords.and === "and1" && ExpressionAttrNamesPkKeywords.source === "source1") + .filter(ExpressionAttrNamesPkKeywords.ttl.notExists) + for { + result <- query.execute + } yield assert(result._1)(hasSize(equalTo(0))) + } + }, + test("querySome should handle keywords in primary key name using low level API") { + withPkKeywordsTable { tableName => + val query = DynamoDBQuery + .querySome[ExpressionAttrNames](tableName, 1) + .whereKey(partitionKey("and") === "and1" && sortKey("source") === "source1") + .filter(ExpressionAttrNames.ttl.notExists) + for { + result <- query.execute + } yield assert(result._1)(hasSize(equalTo(0))) + } } ), suite("keywords in expression attribute names")( diff --git a/dynamodb/src/main/scala/zio/dynamodb/KeyConditionExpression.scala b/dynamodb/src/main/scala/zio/dynamodb/KeyConditionExpression.scala index ff40d4862..3bf382f4b 100644 --- a/dynamodb/src/main/scala/zio/dynamodb/KeyConditionExpression.scala +++ b/dynamodb/src/main/scala/zio/dynamodb/KeyConditionExpression.scala @@ -30,8 +30,8 @@ sealed trait KeyConditionExpression extends Renderable { self => object KeyConditionExpression { - def getOrInsert[From](primaryKeyName: String): AliasMapRender[String] = - AliasMapRender.getOrInsert(ProjectionExpression.MapElement[From, String](Root, primaryKeyName)) + def getOrInsert[From, To](primaryKeyName: String): AliasMapRender[String] = + AliasMapRender.getOrInsert(ProjectionExpression.MapElement[From, To](Root, primaryKeyName)) private[dynamodb] final case class And(left: PartitionKeyExpression, right: SortKeyExpression) extends KeyConditionExpression def partitionKey(key: String): PartitionKey = PartitionKey(key)