driver_go110.go 981 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2018 The Go-MySQL-Driver Authors. All rights reserved.
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public
  6. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  7. // You can obtain one at http://mozilla.org/MPL/2.0/.
  8. // +build go1.10
  9. package mysql
  10. import (
  11. "database/sql/driver"
  12. )
  13. // NewConnector returns new driver.Connector.
  14. func NewConnector(cfg *Config) (driver.Connector, error) {
  15. cfg = cfg.Clone()
  16. // normalize the contents of cfg so calls to NewConnector have the same
  17. // behavior as MySQLDriver.OpenConnector
  18. if err := cfg.normalize(); err != nil {
  19. return nil, err
  20. }
  21. return &connector{cfg: cfg}, nil
  22. }
  23. // OpenConnector implements driver.DriverContext.
  24. func (d MySQLDriver) OpenConnector(dsn string) (driver.Connector, error) {
  25. cfg, err := ParseDSN(dsn)
  26. if err != nil {
  27. return nil, err
  28. }
  29. return &connector{
  30. cfg: cfg,
  31. }, nil
  32. }