Skip to content

Commit

Permalink
Use mysql.NewConfig() instead of mysql.Config{}
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Apr 30, 2024
1 parent ceae1e1 commit 99bbecf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
26 changes: 12 additions & 14 deletions _content/doc/database/open-handle.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ to build a connection string.

```
// Specify connection properties.
cfg := mysql.Config{
User: username,
Passwd: password,
Net: "tcp",
Addr: "127.0.0.1:3306",
DBName: "jazzrecords",
}
cfg := mysql.NewConfig()
cfg.User = username
cfg.Passwd = password
cfg.Net = "tcp"
cfg.Addr = "127.0.0.1:3306"
cfg.DBName = "jazzrecords"
// Get a database handle.
db, err = sql.Open("mysql", cfg.FormatDSN())
Expand All @@ -143,13 +142,12 @@ create a handle with code such as the following:

```
// Specify connection properties.
cfg := mysql.Config{
User: username,
Passwd: password,
Net: "tcp",
Addr: "127.0.0.1:3306",
DBName: "jazzrecords",
}
cfg := mysql.NewConfig()
cfg.User = username
cfg.Passwd = password
cfg.Net = "tcp"
cfg.Addr = "127.0.0.1:3306"
cfg.DBName = "jazzrecords"
// Get a driver-specific connector.
connector, err := mysql.NewConnector(&cfg)
Expand Down
30 changes: 15 additions & 15 deletions _content/doc/tutorial/database-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ specific database.
var db *sql.DB
func main() {
// Capture connection properties.
cfg := mysql.Config{
User: os.Getenv("DBUSER"),
Passwd: os.Getenv("DBPASS"),
Net: "tcp",
Addr: "127.0.0.1:3306",
DBName: "recordings",
}
// Capture connection properties.
cfg := mysql.NewConfig()
cfg.User = os.Getenv("DBUSER")
cfg.Passwd = os.Getenv("DBPASS")
cfg.Net = "tcp"
cfg.Addr = "127.0.0.1:3306"
cfg.DBName = "recordings"
// Get a database handle.
var err error
db, err = sql.Open("mysql", cfg.FormatDSN())
Expand Down Expand Up @@ -690,13 +690,13 @@ type Album struct {
func main() {
// Capture connection properties.
cfg := mysql.Config{
User: os.Getenv("DBUSER"),
Passwd: os.Getenv("DBPASS"),
Net: "tcp",
Addr: "127.0.0.1:3306",
DBName: "recordings",
}
cfg := mysql.NewConfig()
cfg.User = os.Getenv("DBUSER")
cfg.Passwd = os.Getenv("DBPASS")
cfg.Net = "tcp"
cfg.Addr = "127.0.0.1:3306"
cfg.DBName = "recordings"
// Get a database handle.
var err error
db, err = sql.Open("mysql", cfg.FormatDSN())
Expand Down

0 comments on commit 99bbecf

Please sign in to comment.