You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Issues with updating a Data Model
Currently we use two database operations: Read and subsequently Update. Actually that can be just Update:
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.
would result in
which is wrong and would overwrite the correct values of the attributes age and email.
The text was updated successfully, but these errors were encountered: