shad-go/lectures/07-sql/tx/tx.go

14 lines
219 B
Go
Raw Normal View History

2020-04-08 19:20:23 +00:00
tx, err := db.BeginTx(ctx, nil)
if err != nil {
log.Fatal(err)
}
defer tx.Rollback()
if _, err = tx.ExecContext(ctx, ...); err != nil {
log.Fatal(err)
}
if err = tx.Commit(); err != nil {
log.Fatal(err)
}