sqlx-transactionmanager
sqlx-transactionmanager copied to clipboard
Issues with Standard example
In README.md -> Synopsis -> Standard example
defer func() {
if err := tx.Rollback(); err != nil {
// Actually, you should do something...
panic(err)
}
}()
tx.MustExec("INSERT INTO person (first_name, last_name, email) VALUES (?, ?, ?)", "Code", "Hex", "[email protected]")
tx.MustExec("UPDATE person SET email = ? WHERE first_name = ? AND last_name = ?", "[email protected]", "Code", "Hex")
var p Person
if err := tx.Get(&p, "SELECT * FROM person LIMIT 1"); err != nil {
return err
}
// transaction commits
if err := tx.Commit(); err != nil {
return err
}
Issues:
- If tx.Get return err, neither Rollback nor Commit will be called;
- The tx.Rollback in defer will be called, even if tx.Commit have been called;
@ans- Thanks for the report. I haven't maintained it for a long time, so I will investigate and fix it.