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