Skip to content

Instantly share code, notes, and snippets.

@shumon84
Created November 22, 2018 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shumon84/fcc39f479d2577fe2467ee379026325a to your computer and use it in GitHub Desktop.
Save shumon84/fcc39f479d2577fe2467ee379026325a to your computer and use it in GitHub Desktop.
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func main() {
db, _ := sql.Open("mysql", "user:password@tcp(host:port)/dbname")
tx, _ := db.Begin()
// 何かクエリを発行する
// 何かの処理で問題が起こったとき
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment