Skip to content

Instantly share code, notes, and snippets.

@dipeshhkc
Created April 26, 2021 11:52
Show Gist options
  • Save dipeshhkc/89e91e9fa71a7ae0e47264f5ce8d85c9 to your computer and use it in GitHub Desktop.
Save dipeshhkc/89e91e9fa71a7ae0e47264f5ce8d85c9 to your computer and use it in GitHub Desktop.
// begin a transaction
tx := db.Begin()
// do some database operations in the transaction (use 'tx' from this point, not 'db')
tx.Create(...)
// ...
// rollback the transaction in case of error
tx.Rollback()
// Or commit the transaction
tx.Commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment