I want to call some stored procedure from Go that has transactions to make the execution atomic.
I read this article here: http://go-database-sql.org/modifying.html
You should not mingle the use of transaction-related functions such as Begin() and Commit() with SQL statements such as BEGIN and COMMIT in your SQL code. Bad things might result
It says that I should avoid using BEGIN / COMMIT, and I also assume START TRANSACTION in my SQL if I use Begin() and Commit().
What if I made a stored procedure that contained START TRANSACTION and COMMIT.
Could I just skip the Begin() and Commit() functions in Go, and just do an Exec() like this?
query := `CALL comment_branch_delete(?, ?);`
if _, err := mysql.DB.Exec(query, commentId, postId); err != nil {
return err
}
Would this be atomic? If the comment_branch_delete stored procedure contains START TRANSACTION
AND COMMIT
?
Or should I use Tx variable?