sqlx

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

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

func BuildDataSourceName(uname, passwd, ip string, port int, dbname string) (dsn string)

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

type MySQLOption func(*sql.DB)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL