schema.NewTable using regular golang *sql.DB #151
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
The current
schema
package should be able to be used independently of the other packages here. However, this is not true in the current implementation as in order to create a newschema.Table
, it requires something that implementsmysql.Executor
as a connection. As far as I can tell, this requiresmysql.Client
.Since it is likely that many people will use the default
*sql.DB
as their method of accessing mysql elsewhere in their code base, this means one must open a new connection to the database usingmysql.Client
if they want to use theschema
package, which is not really ideal.This PR allows
schema.NewTable
to accept a*sql.DB
object and use that to fetch the table schema.The current draw back is the code is kind of duplicated, although I'm not sure how to make it better. I've also tried to make
*sql.DB
implementmysql.Executor
, but I don't really know how to initialize and populate the correct*mysql.Result
.