Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ConditionCheck type public #550

Open
googley42 opened this issue Dec 8, 2024 · 0 comments
Open

Make ConditionCheck type public #550

googley42 opened this issue Dec 8, 2024 · 0 comments

Comments

@googley42
Copy link
Contributor

googley42 commented Dec 8, 2024

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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant