Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlkit

package
v0.10.6 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(cfg *Config) (*sql.DB, error)

NewDB returns a new sql.DB

func SetLogger

func SetLogger(fn internal.LogFunc)

func Transaction

func Transaction(ctx context.Context, db *sql.DB, fn func(ctx context.Context, tx *sql.Tx) error, opts ...*sql.TxOptions) (err error)

Transaction 执行数据库事务

func TransactionX

func TransactionX(ctx context.Context, db DB, fn func(ctx context.Context, tx TX) error, opts ...*sql.TxOptions) (err error)

TransactionX 执行多数据库事务

Types

type Config

type Config struct {
	// Driver 驱动名称
	//  [-MySQL] mysql
	//  [-PgSQL] pgx
	//  [SQLite] sqlite3
	Driver string `json:"driver" mapstructure:"driver"`
	// DSN 数据源名称
	//
	//  [-MySQL] <username>:<password>@tcp(<host>:3306)/<db>?timeout=10s&charset=utf8mb4&parseTime=True&loc=Local
	//  [-PgSQL] postgres://<username>:<password>@<host>:5432/<dbname>
	//  [SQLite] file::memory:?cache=shared || file:</path/test.db>
	DSN string `json:"dsn" mapstructure:"dsn"`
	// Options 数据库连接池选项
	Options Options `json:"options" mapstructure:"options"`
}

Config 数据库初始化配置

type DB

type DB = map[string]*sql.DB

type Options added in v0.9.1

type Options struct {
	// MaxOpenConns 设置最大可打开的连接数
	MaxOpenConns int `json:"max_open_conns" mapstructure:"max_open_conns"`
	// MaxIdleConns 连接池最大闲置连接数
	MaxIdleConns int `json:"max_idle_conns" mapstructure:"max_idle_conns"`
	// ConnMaxIdleTime 连接最大闲置时间(单位:秒)
	ConnMaxIdleTime int `json:"conn_max_idle_time" mapstructure:"conn_max_idle_time"`
	// ConnMaxLifetime 连接的最大生命时长(单位:秒)
	ConnMaxLifetime int `json:"conn_max_lifetime" mapstructure:"conn_max_lifetime"`
}

type TX

type TX = map[string]*sql.Tx

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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