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

Updating item SET IF_NOT_EXISTS and LIST_APPEND expected behavior #370

Open
michael-pont opened this issue Oct 23, 2023 · 0 comments
Open

Comments

@michael-pont
Copy link
Contributor

I wanted to do an update to an item which has an optional field that can be undefined or is a list of strings.
The expected behavior from the following code is that if the field doesn't exist then then a new list will be created with that particular string. If the list already does exist then an item will be appended to the list. What I found is that the order of the operation matters.

const transaction = new WriteTransaction().addUpdateItem<UserEntity>(
  UserEntity,
  {
    id: '6175f565-3988-4703-ab62-bdf947b184a0',
  },
  {
    nudgeIds: {
      SET: {
        IF_NOT_EXISTS: ['08d02911-5255-4e93-86ea-47a0b18cf78a'],
        LIST_APPEND: ['08d02911-5255-4e93-86ea-47a0b18cf78a'],
      },
    },
  },
);

In this scenario above the LIST_APPEND is never triggered even though the item already exists.
If I switch the order of LIST_APPEND and IF_NOT_EXISTS then the item gets added. However, if the item does not exist then the transaction fails because the IF_NOT_EXISTS does not get triggered first.

nudgeIds: {
  SET: {
    LIST_APPEND: ['08d02911-5255-4e93-86ea-47a0b18cf78a'],
    IF_NOT_EXISTS: ['08d02911-5255-4e93-86ea-47a0b18cf78a'],
  },
},

Is this behavior expected? Is it possible to achieve what I described?

Other Info
Using Typedorm 1.15.4

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