From f88a1fbd2ce730793fb77af9dd1713b2e95968df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 6 Dec 2024 10:28:13 +0100 Subject: [PATCH 1/3] driver: allow configuration of the driver name --- driver/driver.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/driver/driver.go b/driver/driver.go index 4054db2af..fa36dc8e0 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -389,13 +389,15 @@ func (r *rows) Next(dest []sqldriver.Value) error { return nil } +var driverName = "mysql" + func init() { options["compress"] = CompressOption options["collation"] = CollationOption options["readTimeout"] = ReadTimeoutOption options["writeTimeout"] = WriteTimeoutOption - sql.Register("mysql", driver{}) + sql.Register(driverName, driver{}) } // SetCustomTLSConfig sets a custom TLSConfig for the address (host:port) of the supplied DSN. From 529a1ab186d3acfccf72074006570af196c4ce18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 6 Dec 2024 10:35:39 +0100 Subject: [PATCH 2/3] Update README --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index a768a3747..acf684c0f 100644 --- a/README.md +++ b/README.md @@ -455,6 +455,19 @@ func main() { } ``` +### Custom Driver Name + +A custom driver name can be set via build options: `-ldflags '-X "github.com/go-mysql-org/go-mysql/driver.driverName=gomysql"'`. + +This can be useful when using [GORM](https://gorm.io/docs/connecting_to_the_database.html#Customize-Driver): +```go +mysql.Config{ + DriverName: "gomysql", + ... +} + +``` + ### Custom NamedValueChecker Golang allows for custom handling of query arguments before they are passed to the driver From 518f06f44afbc742aec3d707f9209cd0001b3b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 6 Dec 2024 10:38:28 +0100 Subject: [PATCH 3/3] Update README --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index acf684c0f..210b764de 100644 --- a/README.md +++ b/README.md @@ -460,12 +460,18 @@ func main() { A custom driver name can be set via build options: `-ldflags '-X "github.com/go-mysql-org/go-mysql/driver.driverName=gomysql"'`. This can be useful when using [GORM](https://gorm.io/docs/connecting_to_the_database.html#Customize-Driver): + ```go -mysql.Config{ - DriverName: "gomysql", - ... -} +import ( + _ "github.com/go-mysql-org/go-mysql/driver" + "gorm.io/driver/mysql" + "gorm.io/gorm" +) +db, err := gorm.Open(mysql.New(mysql.Config{ + DriverName: "gomysql", + DSN: "gorm:gorm@127.0.0.1:3306/test", +})) ``` ### Custom NamedValueChecker