Go Database/sql Source Analysis (ii) driver package design philosophy

Source: Internet
Author: User
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}                                                                                                     ~                                                                                                               


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.