You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use transactions with sqlboiler with psql and I want to confirm my usage of Rollback() and Confirm()
For example, if I begin a transaction and I detect an error and want to abort the transaction, should I call Rollback()? Or is it sufficient to simply not call Commit()?
tx, _:= db.BeginTx(...)
// on error, abort the transactionifsome_error {
tx.Rollback() // <-- do we need to rollback, or can we just return out?return
}
// no error, commit the transactiontx.Commit()
The text was updated successfully, but these errors were encountered:
You always need to explicitly rollback or commit a transaction (this isn't really a part of sqlboiler fwiw). The way I handle this in a program is with a helper:
helpers.Tx(ctx, db, true, func (tx*sql.Tx) error {
err:=// do something databaseyiferr!=nil {
returnerr// The helper will automatically rollback for you here
}
returnnil// The helper will automatically call commit since you returned nil
})
Hi,
I'm trying to use transactions with sqlboiler with psql and I want to confirm my usage of
Rollback()
andConfirm()
For example, if I begin a transaction and I detect an error and want to abort the transaction, should I call
Rollback()
? Or is it sufficient to simply not callCommit()
?The text was updated successfully, but these errors were encountered: