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

Consider making Tx an interface to facilitate other implementations of the store interface #228

Open
maplebed opened this issue Aug 28, 2018 · 0 comments
Labels
help wanted Feel free to contribute! proposal A suggestion for a change, feature, enhancement, etc
Milestone

Comments

@maplebed
Copy link

I am trying to provide wrappers for common libraries to make it easier to send instrumentation information about the library's use to a 3rd party platform. The struct types in both sql and sqlx make this difficult, but I was happy to see that pop has a store interface. Implementing this interface as a wrapper around sqlx that emits information about the database calls looks like it can work very well. I have a proof of concept wrapper and an example that uses it to demonstrate what I mean.

The challenge comes partly with NamedStmt (though its use in pop seems limited, if I'm reading it right) and mostly with the Transaction calls. Because the store interface's Transaction function returns a *Tx type and the *Tx type embeds sqlx.Tx, it is impossible to get information about a transaction except for its initial creation. Any following statements that happen directly on the Tx type (including commits and rollbacks) are impossible to capture as a wrapper.

If the pop.Tx type were an interface instead of a struct type, I could implement a wrapper that passes through all future sql statements that happen during the transaction.

While the full surface of a sqlx.Tx is rather large (25 functions), the number of functions in the pop.Tx interface could be significantly smaller, in the same way that the store interface is significantly smaller than the full sqlx surface.

@stanislas-m stanislas-m added enhancement help wanted Feel free to contribute! labels Aug 30, 2018
@stanislas-m stanislas-m added proposal A suggestion for a change, feature, enhancement, etc and removed proposal A suggestion for a change, feature, enhancement, etc enhancement labels Oct 31, 2018
@sio4 sio4 added this to the Proposal milestone Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Feel free to contribute! proposal A suggestion for a change, feature, enhancement, etc
Projects
None yet
Development

No branches or pull requests

3 participants