Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: database/sql: Check if Tx has already been committed or rolled back #38012

Open
pjebs opened this issue Mar 22, 2020 · 3 comments
Open

proposal: database/sql: Check if Tx has already been committed or rolled back #38012

pjebs opened this issue Mar 22, 2020 · 3 comments
Labels
Projects
Milestone

Comments

@pjebs
Copy link
Contributor

@pjebs pjebs commented Mar 22, 2020

I have a use case where I would like to know if Tx has already been committed or rolledback. I can't track this information myself because it's for a package that is intended to be used by third parties.

Currently I have to perform a "fake" query on the Tx to check if it returns sql.ErrTxDone. This is ok if the transaction has in fact been committed or rolledback. But if it hasn't, then it will actually take time to call the query.

I believe the object internally tracks this information and it would be good if it was exposed.

@gopherbot gopherbot added this to the Proposal milestone Mar 22, 2020
@gopherbot gopherbot added the Proposal label Mar 22, 2020
@kardianos
Copy link
Contributor

@kardianos kardianos commented Jun 7, 2020

This is an interesting proposal.

Could you explain a bit of the backstory about why you are checking to see if Tx has been committed or rolled back?

@pjebs
Copy link
Contributor Author

@pjebs pjebs commented Jun 8, 2020

I actually can't remember much anymore because it was for some contract work I did for a random client many months ago.

I vaguely remember it was a package with a function to be used by a third party user. The third party user provides a *Tx object to the function.

The adjustment to be made is:

func (tx *Tx) IsDone() bool {
   tx.closemu.RLock()
   defer tx.closemu.RUnlock()
   return tx.isDone()
}
@kardianos
Copy link
Contributor

@kardianos kardianos commented Jun 9, 2020

That is certainly a fine implementation, but without a concrete use case the proposal won't go anywhere.

@rsc rsc added this to Incoming in Proposals Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Incoming
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.