On this week I have been thinking about SQL transactions and how it can be used in WordPress. Right now we only have functions like
But what if you should insert multiple values at the same time? Of course, you can go through step by step and insert (or update) each part of your data via small portions. It may raise an unexpected system behavior in some cases.
Imagine that your PHP script is executing code which should validate and save some data from an external request. During the process, you can save only half of this data and on the one the next step you can catch an error which signals that data was not saved. Some of the data was already replaced by new values and you should answer with 200 or 400 status code. What you will do? That’s why transactions are important.
I will think about this issue in conjunction with WP Kit Data components. I am interested in refactoring this part of the library but not decided how exactly should new flow of data saving looks like.