sqlx-transactionmanager icon indicating copy to clipboard operation
sqlx-transactionmanager copied to clipboard

Issues with Standard example

Open ans- opened this issue 3 years ago • 1 comments

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:

  1. If tx.Get return err, neither Rollback nor Commit will be called;
  2. The tx.Rollback in defer will be called, even if tx.Commit have been called;

ans- avatar Nov 10 '21 10:11 ans-

@ans- Thanks for the report. I haven't maintained it for a long time, so I will investigate and fix it.

Code-Hex avatar Nov 10 '21 10:11 Code-Hex