I used to do Java development and with JPA, I don't really have to worry about the synchronicity between a table and the lists it owns. For those who don't understand what I mean, here's an example.
Suppose you have a Person table and an Address table. A person can have many addresses. So when you update the person's addresses and you're using JPA. Once you persist, the magic happens behind and everything is updated magically (addresses that should be deleted are deleted and those that are updated were updated).
Fast-forward to now, I'm doing NodeJS development and I notice that although we are using flex and some internal libraries to help with building the SQL queries, I can't do what's described above. Currently, there's 2 way that I can think of to do this.
I can delete all addresses that belongs to the person and re-create them. However, doing this means I lose all the metadata that might be useful for logging.
I need to perform extra query to the database to retrieve the previous list of addresses and then perform a for loop to check which address_id should be deleted, updated or created. This is not scalable if the list becomes too large.
So other than the 2 suggestions above, do you guys have any good methods? I can't find any good Persistence adapter for MySQL and NodeJS so far that doesn't have too much dependencies (npm nightmare right there) so it would be good if the solution could be implemented without a 3rd party library/framework.