Go Database/sql Source Analysis (i) SQL package design philosophy

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Database/sql design philosophy is very elegant, but the internal implementation is very much copied, this section from the top floor to analyze the realization of the idea of Database/sql

Provides a standard API for upper-level applications


defines a standard interface layer for the drive layer
Isolate a specific database
Each specific database-driven implementation of the interface can be used

Application layer invocation logic does not depend on a specific database, it uses the standard API provided by SQL


three major functions
Implement a connection pool internally
Internal security for concurrent access through locks

Automatic conversion of internally implemented data types


the interface that the drive layer implements and the calling interface of the application layer are almost identical
The consistency of the interface perspective that the application caller and the driven implementation see

is also a programming philosophy: enhanced functionality but the invocation of the interface is not changed, the general understanding is that the enhancement function to increase the interface, but the implementation of the SQL package has almost no increase in the number of call interface and implementation enhancements


implement complex functions within SQL package
Concurrency-Safe support
Management of connection Pools

Provides an abstraction for accessing the DB without seeing the connection, and the connection is completely hidden in the internal implementation


Programming Philosophy
interface-Oriented programming
The implementation of the SQL package tells us how to implement the abstract platform-based middleware in textbook.
Abstract bottom-Level implementation interface
Middleware implements platform level logic for interface layer
Provides a unified set of calling APIs to isolate the underlying and upper-level callers
The platform-type middleware based on this kind of thought can be abstract:
Log records
Log to File
Log to DB

Write to Network


Session Management
Store in memory
stored in DB

Store in File


Program Configuration
Various configuration files
Db

Other middleware


combination-oriented programming
The SQL package defines the data structure that combines the interface variables and internal data elements of the driver layer

This can be seen as a unique combination of Golang programming patterns


Tiered Implementation
High cohesion within the layer, low coupling between layers
Hiding the complexity of implementation through interface bonding

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.