-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add Queryable interface #809
base: master
Are you sure you want to change the base?
Conversation
When writing applications it's useful to pass a sqlx.DB and a sqlx.Tx interchangeably so that you can compose functions that are runnable in isolation or as part of a transaction. This introduces the Queryable interface, which includes the common exportable methods shared between sqlx.DB and sqlx.Tx so users of the package don't have to implement it themselves. This also adds tests that validate any new shared methods are added to the interface.
This is actually very helpful, even tho it hasn't being merged yet, but it does help me to implement Unit of Work |
Also wanted to add that this abstraction eliminated considerable code from my project. Would love for this to be part of and be maintained by the package. For now I'm using the proposed interface |
I think it would make more sense to split the giant interface into a bunch of smaller ones. I do completely agree that having the common methods to The Queryable interface carries a lot more functionality than is usually needed(in the use cases that I've seen). Instead, having interfaces like: I think that composing Queryable out of smaller interfaces would also tie in better with the current style. There already are some interfaces like that. |
I haven't had a chance to discuss this with @ardan-bkennedy; that's why the label is set to I think we don't need this interface in the package at all. This should be an application concern to define/use. That way, the application establishes the functionality it expects. We should ensure that both |
This interface already exists and I use it today to substitute a DB for a Tx when needed. sqlx.ExtContext I haven't looked too closely to this issue, but why won't this interface work for you? |
I came across #344 and thought it may be useful to open a PR proposing this change since it looks like a few folks could find it useful.
When writing applications it's useful to pass a sqlx.DB and a sqlx.Tx
interchangeably so that you can compose functions that are runnable in
isolation or as part of a transaction.
This introduces the Queryable interface, which includes the common
exportable methods shared between sqlx.DB and sqlx.Tx so users of the
package don't have to implement it themselves.
This also adds tests that validate any new shared methods are
added to the interface.