sqlkit

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 10 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
	// 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
	// MaxOpenConns 设置最大可打开的连接数
	MaxOpenConns int
	// MaxIdleConns 连接池最大闲置连接数
	MaxIdleConns int
	// ConnMaxIdleTime 连接最大闲置时间
	ConnMaxIdleTime time.Duration
	// ConnMaxLifetime 连接的最大生命时长
	ConnMaxLifetime time.Duration
}

Config 数据库初始化配置

type DB

type DB = map[string]*sql.DB

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