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

When updating a record directly use an update statement instead of first reading the record. #111

Open
coeit opened this issue Apr 29, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@coeit
Copy link
Member

coeit commented Apr 29, 2020

Issues with updating a Data Model

Currently we use two database operations: Read and subsequently Update. Actually that can be just Update:

UPDATE persons SET name = ${name} ... WHERE id = ${input.personId}`

upated the updateOne model function to only use a single update request. For this a helper is needed that builds the statement form the given input arguments.

Note

Problem with using a single operation. Assume the Person data model has three attributes: age, name, and email , but the user only wishes to update name to newName. In that case the input has no values for age nor email, thus we need to be careful when constructing the update SQL statement.

UPDATE persons SET name = ${input.name}, age = ${input.age}, email = ${input.email} WHERE id = ${input.personId}

would result in

UPDATE persons SET name = 'newName', age = undefined, email = undefined WHERE id = 123;

which is wrong and would overwrite the correct values of the attributes age and email.

@coeit coeit added the enhancement New feature or request label Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant