Answer the question
In order to leave comments, you need to log in
What is the best way to update records in a table using data from an external source?
Greetings!
There is an external service from which I request entities with their properties via API. I need to use the received data on my portal, so I put it in the database. The database is necessary in order to: 1) do not go into the API for each sneeze. it's long. 2) in the table, in addition to the received data, all sorts of "options" will be stored, which I myself will put down.
it follows from point 2 that I cannot clean the table and fill it again with each request.
Now I do it using Python: I check for remote entities using sets (in one set, the contents of the table, in the other - the received data, when subtracting the sets, I find the deleted ones), for each received entity, I check its presence in the table ( simple select by unique id) and if there is, then "blindly" update the received properties, or insert into the table. I do not want to show the code, but I can show it on request. The question is actually this: is it right to do this in the application, and not, for example, in the DBMS? Are there any better algorithms for implementing such tasks?
Answer the question
In order to leave comments, you need to log in
in general, it’s good when the logic is concentrated in one place, the program becomes more portable ..
and you can organize the logic in the DBMS if the storage imitates ordinary tables, pretends to be simple .. well, like we hang insert, update, delete triggers on the view
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question