4 ms·
I'm confused. sql.Open's first argument is which driver you want to use, in string format. These drivers become available after they've been imported, and the s
by tokenizerrr 12y ago
I'm confused. sql.Open's first argument is which driver you want to use, in string format. These drivers become available after they've been imported, and the side effects seem insignificant[1]. This seems to make it perfectly possible to use multiple drivers within the same scope. The drivers themselves also seem to have several unit test files, though I can't judge on the quality of those.
[1] https://github.com/go-sql-driver/mysql/blob/master/driver.go#L136 https://github.com/go-sql-driver/mysql/blob/master/driver.go...
- shadowmint 12y agoSee... that's the thing. It might work. If the driver plays nicely. Or it might not. In fact, you have no way of knowing without reading the source code. The sqlite driver used to not work with the postgres one. I don't know why. I never looked into it... but, that this can happen is pretty bad, I'd argue. Packages that invoke code when you import them and require this sort of import: import _ "github.com/go-sql-driver/mysql" Aren't idiomatic. They're hacks, because the database module didn't really consider how it was going to work properly.