I am someone, who is very much interested understanding update operation in sequelize model.update().
Suppose my table is with only one entry: ( assume 'id' is unique, sorted, index )
| id | fname | sname | dob | phone | |
|---|---|---|---|---|---|
| 1 | old_fname | old_sname | old_email | old_dob | old_phone_no |
I have gone through sequelize's official website, sequelize core update method and also in the github implementation of the sequelize-model.update() method . None of these descriptions and comments could answer my questions.
const dataToUpdate = {
fname: new_fname,
sname: old_sname, // Assume, I added it by mistake, same as old value
email: old_email, // Assume, I added it by mistake, same as old value
dob: new_dob,
};
const options = { where : { id : 1 } } ;
sequelize.model.update(dataToUpdate, options);
If this dataToUpdate, would be on Document-based database, then we would have simply overridden entire JSON object(assuming it is stored in JSON like DynamoDB). Only one write operation.(of course, the input format would be different, but, in any format, based on 'id' field, there will be single write operation).
But, I am using row-order postgres database with sequelize.
In this case, how many write operations will be there internally in the database ? Four operations ? or just Two Operations ? Will
snameandemailbe overridden, even tough the values are same for those two columns. Or just one operation (first internallyget()will occur, then old data will be merged with new data, and then old row will be over-written all at once. So total, one read + one write ) ?How is
sequelize.model.update()is implemented forpostgres? I would like to know, if someone can explain me, or may be redirect me to some educational, informative resources which can answer these kind of stupid doubts !
Thanks in advance.
Update:
Upon asking chat-gpt, I got this:
The number of actual database write operations can depend on the underlying implementation details of the database and the ORM (Sequelize in this case). Generally, it's common for an update operation to involve just one write operation. The database engine will handle the update efficiently.