txcheck
is a program for checking that you call Begin
whenever you call DML functions in go programs. Supports database/sql
and github.com/gocraft/dbr
.
go get -u github.com/mcesar/txcheck
For basic usage, just give the package path of interest as the first argument, for example:
txcheck github.com/mcesar/txcheck
Given the following program, txcheck
warns that function main
calls Exec
but does no call Begin
(or BeginTx
).
package main
import (
"context"
"database/sql"
)
var db *sql.DB
func main() {
// tx, _ := db.Begin()
db.Exec("INSERT INTO t(c) values('v');")
// ...
}