Skip to content

Update syntax is clunky when using conditions #38

@jyelewis

Description

@jyelewis
const transaction = this.hashSearchResultCollection.updateTransaction(
  {
    data: result.data,
  },
  {
    bestLeadingZeros: result.leadingZeros,
    bestNum: result.num,
  }
);

// would be nice to inline this
transaction.primaryOperation.condition.bestLeadingZeros = {
  $lt: result.leadingZeros,
};

Additional note: this will unexpectedly throw "Entity not found" if the condition fails, rather than a condition check exception.

Proposed alternate format

this.hashSearchResultCollection.update({
  key: { data: result.data },
  update: {
    bestLeadingZeros: result.leadingZeros,
    bestNum: result.num,
  },
  condition: {
    $lt: result.leadingZeros,
  },
  onConditionFail: THROW | RETURN_CURRENT
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions