mysqlcli

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(addr, user, pwd, dbName string, options ...Option)

Connect 连接数据库

func DB

func DB(ctx context.Context) *gorm.DB

DB 获取数据库连接

func IsRecordNotFoundErr added in v0.9.0

func IsRecordNotFoundErr(err error) bool

IsRecordNotFoundErr 判断是否记录不存在错误

func StartTransaction

func StartTransaction(ctx context.Context, trans TransactionFunc) error

StartTransaction 开启事务

Types

type Option

type Option func(*Options)

func WithIgnoreRecordNotFoundError

func WithIgnoreRecordNotFoundError(ignoreRecordNotFoundError bool) Option

WithIgnoreRecordNotFoundError 忽略记录不存在错误

func WithParameterizedQueries

func WithParameterizedQueries(parameterizedQueries bool) Option

WithParameterizedQueries 使用参数化查询

func WithSilent

func WithSilent(silent bool) Option

WithSilent 设置是否打印sql语句

func WithSlowThreshold

func WithSlowThreshold(slowThreshold time.Duration) Option

WithSlowThreshold 设置慢查询阈值

type Options

type Options struct {
	TablePrefix   string // 表名前缀
	SingularTable bool   // 使用单数表名

	// Logger
	Silent                    bool          // 是否打印sql语句
	ParameterizedQueries      bool          // 使用参数化查询
	IgnoreRecordNotFoundError bool          // 忽略记录不存在错误
	SlowThreshold             time.Duration // 慢查询阈值
}

type TransactionFunc

type TransactionFunc func(tx *gorm.DB) error

Jump to

Keyboard shortcuts

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