2018/10/19

gorm transaction

TransactionsTo perform a set of operations within a transaction, the general flow is as below.
// begin a transaction
tx := db.Begin()

// do some database operations in the transaction (use 'tx' from this point, not 'db')
tx.Create(...)

// ...

// rollback the transaction in case of error
tx.Rollback()

// Or commit the transaction
tx.Commit()