Documentation ¶
Overview ¶
* @Author: cnzf1 * @Date: 2021-06-15 11:58:51 * @LastEditors: cnzf1 * @LastEditTime: 2023-03-01 17:25:15 * @Description: 数据库连接工具类
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDataSourceName ¶
BuildDataSourceName return dsn to username:password@tcp(ip:port)/database?charset=utf8mb4
func NewMySQLInstance ¶
func NewMySQLInstance(dsn string, opts ...MySQLOption) (db *sql.DB, err error)
NewMySQLInstance create a db connection
Types ¶
type MySQLOption ¶
func WithConnMaxLifetime ¶
func WithConnMaxLifetime(d time.Duration) MySQLOption
WithConnMaxLifetime sets the maximum amount of time a connection may be reused. Expired connections may be closed lazily before reuse.
func WithMaxIdleConns ¶
func WithMaxIdleConns(n int) MySQLOption
WithMaxIdleConns sets the maximum number of connections in the idle connection pool.
func WithMaxOpenConns ¶
func WithMaxOpenConns(n int) MySQLOption
WithMaxOpenConns sets the maximum number of open connections to the database.
Click to show internal directories.
Click to hide internal directories.