Created
November 22, 2018 01:28
-
-
Save shumon84/fcc39f479d2577fe2467ee379026325a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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