gormcli

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect added in v0.2.0

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

Connect 连接数据库

func DB

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

DB 获取数据库连接

func StartTransaction added in v0.6.0

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

StartTransaction 开启事务

Types

type Option added in v0.2.0

type Option func(*Options)

func WithIgnoreRecordNotFoundError added in v0.2.0

func WithIgnoreRecordNotFoundError(ignoreRecordNotFoundError bool) Option

WithIgnoreRecordNotFoundError 忽略记录不存在错误

func WithParameterizedQueries added in v0.2.0

func WithParameterizedQueries(parameterizedQueries bool) Option

WithParameterizedQueries 使用参数化查询

func WithSilent added in v0.2.0

func WithSilent(silent bool) Option

WithSilent 设置是否打印sql语句

func WithSlowThreshold added in v0.2.0

func WithSlowThreshold(slowThreshold time.Duration) Option

WithSlowThreshold 设置慢查询阈值

type Options added in v0.2.0

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

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

type TransactionFunc added in v0.6.0

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