Thinking about SQL transactions

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 update_option() or update_post_meta().

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.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s