Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,25 @@ 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
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:[email protected]:3306/test",
}))
```

### Custom NamedValueChecker

Golang allows for custom handling of query arguments before they are passed to the driver
Expand Down
4 changes: 3 additions & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading