zio/zio-dynamodb

Make `ConditionCheck` type public

开放

#550 创建于 2024年12月8日

 (0 条评论) (0 个反应) (0 位负责人)Scala (23 个派生)auto 404
good first issue

仓库指标

星标
 (48 个星标)
PR 合并指标
 (平均合并 3天 12小时) (30 天内合并 49 个 PR)

描述

Reported by @calvinlfer - make ConditionCheck type (which is part of the transaction API) public so that users can use it to ascribe types.

def conditionalCheckAddTransaction(givenP1: DynamoPerson, givenP2: DynamoPerson)(
    write: DynamoPerson
  ): IO[DynamoDBError, Option[DynamoPerson]] =
    def checkPrimaryKeyAndName(p: DynamoPerson) = // can't type ConditionCheck here 
      val primaryKey = (DynamoPerson.pk.partitionKey === p.pk && DynamoPerson.sk.sortKey === p.sk).asAttrMap
      DynamoDBQuery.conditionCheck(table, primaryKey)(
        DynamoPerson.name === p.name
      )

    // given the presence of persons #1 and #2 in the table, we want to write a new person
    val cond1 = checkPrimaryKeyAndName(givenP1)
    val cond2 = checkPrimaryKeyAndName(givenP2)
    val add   = DynamoDBQuery.put(tableName = table, write)
    val txn   = cond1.zipRight(cond2).zipRight(add).transaction
    executor
      .execute(txn)
      .tapSomeError:
        case DynamoDBError.AWSError(cause)
            if cause.awsErrorDetails().errorCode() == "ConditionalCheckFailedException" =>
          ZIO.debug(cause.awsErrorDetails())

贡献者指南