我在用https://pkg.go.dev/github.com/jmoiron/[email protected]連接到 postgres 并進行查詢。如果我的 transaction.Commit 失敗,我應該做 transaction.Rollback例子 tx, err := appState.PgConn.Beginx() if err != nil { return err } // then some queries using this tx reference在那之后,當我們提交事務時,我們應該做..方法 1err:= tx.Commit()if err != nil { return err;}或者我們應該使用方法 2err1 := tx.Commit()if err1 != nil { err2:= tx.Rollback() if err2 !=nil { return err2 }}
- 1 回答
- 0 關注
- 153 瀏覽
添加回答
舉報
0/150
提交
取消