From ec4c43af5d6c316fa9a809a3b8bfa8352bcff940 Mon Sep 17 00:00:00 2001 From: Julien Schmidt Date: Mon, 1 Jul 2013 16:00:57 +0200 Subject: [PATCH 1/2] Export driver struct and improve doc --- README.md | 2 +- driver.go | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8cd6ac38c..83d469d85 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Use `mysql` as `driverName` and a valid [DSN](#dsn-data-source-name) as `dataSo import "database/sql" import _ "github.com/go-sql-driver/mysql" -db, e := sql.Open("mysql", "user:password@/dbname?charset=utf8") +db, err := sql.Open("mysql", "user:password@/dbname") ``` [Examples are available in our Wiki](https://github.com/go-sql-driver/mysql/wiki/Examples "Go-MySQL-Driver Examples"). diff --git a/driver.go b/driver.go index 9ce6f6aaf..a36da310b 100644 --- a/driver.go +++ b/driver.go @@ -6,6 +6,13 @@ // You can obtain one at http://mozilla.org/MPL/2.0/. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package +// +// The driver should be used via the database/sql package: +// +// import "database/sql" +// import _ "github.com/go-sql-driver/mysql" +// +// db, err := sql.Open("mysql", "user:password@/dbname") package mysql import ( @@ -14,12 +21,14 @@ import ( "net" ) -type mysqlDriver struct{} +// This struct is exported to make the driver directly accessible. +// In general the driver is used via the database/sql package. +type MySQLDriver struct{} // Open new Connection. // See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how // the DSN string is formated -func (d *mysqlDriver) Open(dsn string) (driver.Conn, error) { +func (d *MySQLDriver) Open(dsn string) (driver.Conn, error) { var err error // New mysqlConn @@ -78,5 +87,5 @@ func (d *mysqlDriver) Open(dsn string) (driver.Conn, error) { } func init() { - sql.Register("mysql", &mysqlDriver{}) + sql.Register("mysql", &MySQLDriver{}) } From 4cfad3339ea6955e48a5cecd161051395a3ca72d Mon Sep 17 00:00:00 2001 From: Julien Schmidt Date: Mon, 1 Jul 2013 16:04:05 +0200 Subject: [PATCH 2/2] doc: reference the readme --- driver.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/driver.go b/driver.go index a36da310b..8f093c69c 100644 --- a/driver.go +++ b/driver.go @@ -13,6 +13,8 @@ // import _ "github.com/go-sql-driver/mysql" // // db, err := sql.Open("mysql", "user:password@/dbname") +// +// See https://github.com/go-sql-driver/mysql#usage for details package mysql import (