kgorm

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*gorm.DB
	InstanceName string
	Logger       baselogger.Logger
}

func Get

func Get(name string) (*DB, bool)

Get ...

func New

func New(dialector gorm.Dialector, opts ...*Option) (*DB, error)

func (*DB) RegistResolver

func (db *DB) RegistResolver(sources []gorm.Dialector, replicas []gorm.Dialector, datas ...interface{}) (*DB, error)

type Option

type Option struct {
	InstanceName string
	// 最大空闲连接数
	MaxIdleConns int
	// 最大活动连接数
	MaxOpenConns int
	// 连接的最大存活时间
	ConnMaxLifetime string
	// 生成 SQL 但不执行,可以用于准备或测试生成的 SQL
	DryRun bool
	// PreparedStmt 在执行任何 SQL 时都会创建一个 prepared statement 并将其缓存,以提高后续的效率,
	PrepareStmt bool
	// 在完成初始化后,GORM 会自动 ping 数据库以检查数据库的可用性,若要禁用该特性,可将其设置为 true
	DisableAutomaticPing bool
	// 在 AutoMigrate 或 CreateTable 时,GORM 会自动创建外键约束,若要禁用该特性,可将其设置为 true
	DisableForeignKeyConstraintWhenMigrating bool
	// 慢日志阈值
	SlowThreshold          string
	SkipDefaultTransaction bool
	Logger                 baselogger.GormLogger
	TablePrefix            string
	SingularTable          bool
}

func ConfigOption

func ConfigOption(key string) (option *Option, err error)

RawConfig ...

func NewOption

func NewOption() *Option

func SetConnMaxLifetime

func SetConnMaxLifetime(l string) *Option

func SetDisableAutomaticPing

func SetDisableAutomaticPing(l bool) *Option

func SetDisableForeignKeyConstraintWhenMigrating

func SetDisableForeignKeyConstraintWhenMigrating(l bool) *Option

func SetDryRun

func SetDryRun(l bool) *Option

func SetInstanceName

func SetInstanceName(l string) *Option

func SetLogger

func SetLogger(l baselogger.GormLogger) *Option

func SetMaxIdleConns

func SetMaxIdleConns(l int) *Option

func SetMaxOpenConns

func SetMaxOpenConns(l int) *Option

func SetPrepareStmt

func SetPrepareStmt(l bool) *Option

func SetSingularTable

func SetSingularTable(l bool) *Option

func SetSkipDefaultTransaction

func SetSkipDefaultTransaction(l bool) *Option

func SetSlowThreshold

func SetSlowThreshold(l string) *Option

func SetTablePrefix

func SetTablePrefix(l string) *Option

func (*Option) MergeOption

func (c *Option) MergeOption(opts ...*Option) *Option

func (*Option) SetConnMaxLifetime

func (c *Option) SetConnMaxLifetime(l string) *Option

func (*Option) SetDisableAutomaticPing

func (c *Option) SetDisableAutomaticPing(l bool) *Option

func (*Option) SetDisableForeignKeyConstraintWhenMigrating

func (c *Option) SetDisableForeignKeyConstraintWhenMigrating(l bool) *Option

func (*Option) SetDryRun

func (c *Option) SetDryRun(l bool) *Option

func (*Option) SetInstanceName

func (c *Option) SetInstanceName(l string) *Option

func (*Option) SetLogger

func (c *Option) SetLogger(l baselogger.GormLogger) *Option

func (*Option) SetMaxIdleConns

func (c *Option) SetMaxIdleConns(l int) *Option

func (*Option) SetMaxOpenConns

func (c *Option) SetMaxOpenConns(l int) *Option

func (*Option) SetPrepareStmt

func (c *Option) SetPrepareStmt(l bool) *Option

func (*Option) SetSingularTable

func (c *Option) SetSingularTable(l bool) *Option

func (*Option) SetSkipDefaultTransaction

func (c *Option) SetSkipDefaultTransaction(l bool) *Option

func (*Option) SetSlowThreshold

func (c *Option) SetSlowThreshold(l string) *Option

func (*Option) SetTablePrefix

func (c *Option) SetTablePrefix(l string) *Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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