Skip to content

Commit ec4c43a

Browse files
committed
Export driver struct and improve doc
1 parent ff69942 commit ec4c43a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Use `mysql` as `driverName` and a valid [DSN](#dsn-data-source-name) as `dataSo
6060
import "database/sql"
6161
import _ "github.com/go-sql-driver/mysql"
6262

63-
db, e := sql.Open("mysql", "user:password@/dbname?charset=utf8")
63+
db, err := sql.Open("mysql", "user:password@/dbname")
6464
```
6565

6666
[Examples are available in our Wiki](https://github.com/go-sql-driver/mysql/wiki/Examples "Go-MySQL-Driver Examples").

driver.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
// You can obtain one at http://mozilla.org/MPL/2.0/.
77

88
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
9+
//
10+
// The driver should be used via the database/sql package:
11+
//
12+
// import "database/sql"
13+
// import _ "github.com/go-sql-driver/mysql"
14+
//
15+
// db, err := sql.Open("mysql", "user:password@/dbname")
916
package mysql
1017

1118
import (
@@ -14,12 +21,14 @@ import (
1421
"net"
1522
)
1623

17-
type mysqlDriver struct{}
24+
// This struct is exported to make the driver directly accessible.
25+
// In general the driver is used via the database/sql package.
26+
type MySQLDriver struct{}
1827

1928
// Open new Connection.
2029
// See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how
2130
// the DSN string is formated
22-
func (d *mysqlDriver) Open(dsn string) (driver.Conn, error) {
31+
func (d *MySQLDriver) Open(dsn string) (driver.Conn, error) {
2332
var err error
2433

2534
// New mysqlConn
@@ -78,5 +87,5 @@ func (d *mysqlDriver) Open(dsn string) (driver.Conn, error) {
7887
}
7988

8089
func init() {
81-
sql.Register("mysql", &mysqlDriver{})
90+
sql.Register("mysql", &MySQLDriver{})
8291
}

0 commit comments

Comments
 (0)