Using an auxiliary variable in your favor
Create a list that defines the behavior that should be done in JSON itself in each record.
Any record previously sent would have, say, 0, saying it is a pre-existing data not changed.
Have you entered a new record? Assigns another value, such as 1. Here the server knows that it has to execute a INSERT INTO
Have you deleted a record? Oops, but the guy may have deleted something that is not even on the server yet ... so basically
se(action = 0)entao
definir action deste registro 2, para executar DELETE do lado do servidor
senao
só apaga do JSON, não envia pro servidor
The same thing goes for an edit. If the person edit a record that has not yet been inserted into the server you will keep the 1 but will update the data inside the JSON. If the registry existed previously there you set a 3, so that a UPDATE
is executed in the database.
This will prevent you from having to make 1 SELECT
for each record, almost nothing increases the client-side effort, greatly reduces the problem on the server side. (You'll just have to add a switch on the server side if it's already ready)
If you want to further reduce the server-side problem, you can try to filter JSON and send everything that is not 0, so that the server is only in charge of changing the database, not having to keep checking what records were or unaffected.