Skip to content

Conversation

shuhaowu
Copy link
Contributor

@shuhaowu shuhaowu commented Aug 1, 2017

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 new schema.Table, it requires something that implements mysql.Executor as a connection. As far as I can tell, this requires mysql.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 using mysql.Client if they want to use the schema 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 implement mysql.Executor, but I don't really know how to initialize and populate the correct *mysql.Result.

schema/schema.go Outdated
}

func NewTable(conn mysql.Executer, schema string, name string) (*Table, error) {
func NewTable(conn interface{}, schema string, name string) (*Table, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shuhaowu

But I don't like the interface here, the interface has no meaning here. If you want to support sql.DB, I prefer using another function like NewTableFromDB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my original implementation as well. Let me revert this back to that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done.

Copy link
Collaborator

@siddontang siddontang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@siddontang siddontang merged commit db4a35b into go-mysql-org:master Aug 3, 2017
@shuhaowu shuhaowu deleted the schema-tables-regular branch August 3, 2017 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants