-
Notifications
You must be signed in to change notification settings - Fork 1.1k
*sql.DB as an interface #227
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
Comments
it's would be nice, then we can use some wrappers, for example "log sql queries" |
This would definitely be a breaking change, because sqlx.DB exposes the *sql.DB that you pass it, since it gets embedded. It's possible to add an extra interface to the Some of the implications of this are really interesting so I'll have to think about whether it's worth a significant restructuring of the code and a slight increase in the API. |
+1 |
type LoggingDB struct {
*sql.DB
}
func (l *LoggingDB) Query(q string, args ...interface{}) {
logf("%v, %+v\n", q, args)
return l.DB.Query(q, args...)
}
... But I don't see how this can be accomodated in a way that's worth the complexity, especially now that the DB interface has changed so drastically in the latest release. Instead of doing this in sqlx, I suggest you wrap If someone wants to submit a PR that shows how this might look, I'd be willing to entertain it, but it:
I can't see how to achieve all 3 but it may be possible. |
I found it a little weird to use |
I also think it would be nice to wrap
Then in the tests:
However, I can't get this to work since it complains about this error:
|
Actually, found a way around it:
|
I did a quick try of using an interface instead of |
No need to create an interface for sql.DB that everyone can use. That is the great thing about GO is that you can create your own local interface for testing! |
Some interesting options would open up if your NewDB method took an interface that adheres to sql.DB.
The text was updated successfully, but these errors were encountered: