xugu_driver.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package xugu
  2. import (
  3. "context"
  4. "database/sql"
  5. "database/sql/driver"
  6. "fmt"
  7. "time"
  8. )
  9. // XuguDriver is exported to make the driver directly accessible
  10. type XuguDriver struct{}
  11. /* Register Driver */
  12. func init() {
  13. /* Register makes a database driver available by the provided name.
  14. * If Register is called twice with the same name or if driver is nil,
  15. * it panics.
  16. */
  17. sql.Register("xugu", &XuguDriver{})
  18. timezone, _ := time.LoadLocation("Asia/Shanghai")
  19. time.Local = timezone
  20. }
  21. // Open opens a database specified by its database driver name and a
  22. // driver-specific data source name, usually consisting of at least a
  23. // database name and connection information.
  24. //
  25. // Most users will open a database via a driver-specific connection
  26. // helper function that returns a *DB. No database drivers are included
  27. // in the Go standard library. See https://golang.org/s/sqldrivers for
  28. // a list of third-party drivers.
  29. //
  30. // Open may just validate its arguments without creating a connection
  31. // to the database. To verify that the data source name is valid, call
  32. // Ping.
  33. // The returned DB is safe for concurrent use by multiple goroutines
  34. // and maintains its own pool of idle connections. Thus, the Open
  35. // function should be called just once. It is rarely necessary to
  36. // close a DB.
  37. func (db XuguDriver) Open(dsn string) (driver.Conn, error) {
  38. conn := &connector{dsn: dsn}
  39. return conn.Connect(context.Background())
  40. }
  41. func (db XuguDriver) OpenConnector(dsn string) (driver.Connector, error) {
  42. fmt.Println("GlobalIsBig走了吗 ")
  43. return &connector{dsn: dsn}, nil
  44. }