Skip to content

Instantly share code, notes, and snippets.

@agusrichard
Created November 26, 2021 16:35
Show Gist options
  • Save agusrichard/1792b991a817282f07ecc10627daef72 to your computer and use it in GitHub Desktop.
Save agusrichard/1792b991a817282f07ecc10627daef72 to your computer and use it in GitHub Desktop.
tx, err := r.db.Beginx()
if err != nil {
return errors.Wrap(err, "todo repository: create todo: failed to initiate transaction;")
}
err = insertTodo(tx, todo)
if err != nil {
tx.Rollback()
return errors.Wrap(err, "todo repository: create todo: failed to insert todo in repository;")
}
tx.Commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment