File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -460,6 +460,25 @@ func main() {
460460}
461461```
462462
463+ ### Custom Driver Name
464+
465+ A custom driver name can be set via build options: ` -ldflags '-X "github.com/go-mysql-org/go-mysql/driver.driverName=gomysql"' ` .
466+
467+ This can be useful when using [ GORM] ( https://gorm.io/docs/connecting_to_the_database.html#Customize-Driver ) :
468+
469+ ``` go
470+ import (
471+ _ " github.com/go-mysql-org/go-mysql/driver"
472+ " gorm.io/driver/mysql"
473+ " gorm.io/gorm"
474+ )
475+
476+ db , err := gorm.Open (mysql.New (mysql.Config {
477+ DriverName : " gomysql" ,
478+ DSN :
" gorm:[email protected] :3306/test" ,
479+ }))
480+ ```
481+
463482### Custom NamedValueChecker
464483
465484Golang allows for custom handling of query arguments before they are passed to the driver
Original file line number Diff line number Diff line change @@ -389,13 +389,15 @@ func (r *rows) Next(dest []sqldriver.Value) error {
389389 return nil
390390}
391391
392+ var driverName = "mysql"
393+
392394func init () {
393395 options ["compress" ] = CompressOption
394396 options ["collation" ] = CollationOption
395397 options ["readTimeout" ] = ReadTimeoutOption
396398 options ["writeTimeout" ] = WriteTimeoutOption
397399
398- sql .Register ("mysql" , driver {})
400+ sql .Register (driverName , driver {})
399401}
400402
401403// SetCustomTLSConfig sets a custom TLSConfig for the address (host:port) of the supplied DSN.
You can’t perform that action at this time.
0 commit comments