Tuesday, March 14, 2017

Laravel DB transactions with multiple commits?

Can I make some checkpoints during DB transaction?

For example, when the transaction starts, I have many queries, updates, deletes and so on.

DB::transaction(function () {
    DB::table('users')->update(['votes' => 1]);
    // something else here
    DB::table('posts')->delete();
});

As far as I understand, this kind of function would automatically commit everything in case of success and rollback if something goes wrong.

But would it be possible not to rollback everything in case of error, for example, like

DB::table('users')->update(['votes' => 1]);
// something else here
DB::if_successful_so_far_do_not_rollback_previous_lines();
DB::table('posts')->delete();

Do any "small inner commits" exist?



via Yawning Milk

Advertisement