Skip to content

Commit f82b14f

Browse files
committed
Merge pull request #104 from go-sql-driver/driver
Export driver struct and improve doc
2 parents 2f1342a + 4cfad33 commit f82b14f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-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: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
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")
16+
//
17+
// See https://github.com/go-sql-driver/mysql#usage for details
918
package mysql
1019

1120
import (
@@ -14,12 +23,14 @@ import (
1423
"net"
1524
)
1625

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

1930
// Open new Connection.
2031
// See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how
2132
// the DSN string is formated
22-
func (d *mysqlDriver) Open(dsn string) (driver.Conn, error) {
33+
func (d *MySQLDriver) Open(dsn string) (driver.Conn, error) {
2334
var err error
2435

2536
// New mysqlConn
@@ -78,5 +89,5 @@ func (d *mysqlDriver) Open(dsn string) (driver.Conn, error) {
7889
}
7990

8091
func init() {
81-
sql.Register("mysql", &mysqlDriver{})
92+
sql.Register("mysql", &MySQLDriver{})
8293
}

0 commit comments

Comments
 (0)