zio/zio-dynamodb

Make `ConditionCheck` type public

Offen

#550 geöffnet am 08.12.2024

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Scala (23 Forks)auto 404
good first issue

Repository-Metriken

Stars
 (48 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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())

Contributor Guide