Skip to content

Conversation

@dveeden
Copy link
Collaborator

@dveeden dveeden commented Dec 6, 2024

When using gorm one can use a custom driver: https://gorm.io/docs/connecting_to_the_database.html#Customize-Driver

However as both go-mysql and go-sql-driver/mysql register the driver name mysql this leads to a conflict:

$ go run main.go
panic: sql: Register called twice for driver mysql

goroutine 1 [running]:
database/sql.Register({0x88bbfc, 0x5}, {0x961fc0, 0xcb3cc0})
	/usr/lib/golang/src/database/sql/sql.go:62 +0x128
github.com/go-mysql-org/go-mysql/driver.init.0()
	/home/dvaneeden/dev/go-mysql/driver/driver.go:400 +0x133
exit status 2

Normally one would not import both in the same project, but gorm.io/driver/mysql depends on github.com/go-sql-driver/mysql, so that's not really possible when using gorm.

This PR makes it possible to set the driver name like this:

-ldflags '-X "github.com/go-mysql-org/go-mysql/driver.driverName=gomysql"'

@lance6716 lance6716 merged commit c6114ee into go-mysql-org:master Dec 6, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants