38 lines
981 B
Go
38 lines
981 B
Go
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
|
|
//
|
|
// Copyright 2018 The Go-MySQL-Driver Authors. All rights reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
// +build go1.10
|
|
|
|
package mysql
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
)
|
|
|
|
// NewConnector returns new driver.Connector.
|
|
func NewConnector(cfg *Config) (driver.Connector, error) {
|
|
cfg = cfg.Clone()
|
|
// normalize the contents of cfg so calls to NewConnector have the same
|
|
// behavior as MySQLDriver.OpenConnector
|
|
if err := cfg.normalize(); err != nil {
|
|
return nil, err
|
|
}
|
|
return &connector{cfg: cfg}, nil
|
|
}
|
|
|
|
// OpenConnector implements driver.DriverContext.
|
|
func (d MySQLDriver) OpenConnector(dsn string) (driver.Connector, error) {
|
|
cfg, err := ParseDSN(dsn)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &connector{
|
|
cfg: cfg,
|
|
}, nil
|
|
}
|