This is a creation in Article, where the information may have evolved or changed.
Drive Interface design features
The drive layer design is simple, without the control of concurrent locks
The design of the drive layer is based on a single connection, without considering the connection pool
The drive layer transaction TX and stmt are separated independently, TX only two simple methods are commit () and rollback ()
Drive-specific implementations need to implement the API interface of the driver layer on a single connection
Data structure of driver package
Call relationship
Driver Registration
The specific database driver only needs to follow the interface layer definition, implements the API, and then registers in the SQL Packet's global drive slicing sql.drivers.
var ( driversmu sync. Rwmutex Drivers = Make (map[string]driver. Driver) (name string, Driver Driver.) Driver) {
MySQL driver github.com/go-sql-driver/mysql registration process:
Src/github.com/go-sql-driver/mysql/driver.go
165 func init () { 166 sql. Register ("MySQL", &mysqldriver{}) 167} ~