xdb

package module
v0.0.0-...-d05db29 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(option Option) (*gorm.DB, error)

New 实例化

func RemoveDriver

func RemoveDriver(names ...string)

RemoveDriver 移除驱动

func SetDriver

func SetDriver(name string, driver Driver)

SetDriver 设置数据库驱动

func SetIsMigration

func SetIsMigration(b bool)

SetIsMigration 设置是否是迁移模式

Types

type Driver

type Driver func(link string) gorm.Dialector

Driver database driver handler

type NamingStrategy

type NamingStrategy struct {
	schema.NamingStrategy
	// contains filtered or unexported fields
}

NamingStrategy Customized naming policy

func (NamingStrategy) CheckerName

func (ns NamingStrategy) CheckerName(table, column string) string

CheckerName generate checker name

func (NamingStrategy) IndexName

func (ns NamingStrategy) IndexName(table, column string) string

IndexName generate index name

func (NamingStrategy) JoinTableName

func (ns NamingStrategy) JoinTableName(table string) string

JoinTableName convert string to join table name

func (NamingStrategy) RelationshipFKName

func (ns NamingStrategy) RelationshipFKName(rel schema.Relationship) string

RelationshipFKName generate fk name for relation

func (NamingStrategy) SchemaName

func (ns NamingStrategy) SchemaName(table string) string

SchemaName generate schema name from table name, don't guarantee it is the reverse value of TableName

func (NamingStrategy) TableName

func (ns NamingStrategy) TableName(str string) string

TableName 表名替换

type Option

type Option struct {
	Driver        string        `json:"driver"`                       // Driver 数据库的驱动,默认支持 mysql, sqlite, postgres, sqlserver, 同样支持自定义驱动
	Link          string        `json:"link"`                         // Link 数据库连接地址
	Prefix        string        `json:"prefix"`                       // Prefix 数据表前缀
	Sources       []string      `json:"sources"`                      // Sources 主库连接
	Replicas      []string      `json:"replicas"`                     // Replicas 从库连接
	Policy        string        `json:"policy"`                       // Policy 主从策略
	LocalTime     bool          `json:"localTime"`                    // LocalTime 是否本地时间
	DryRun        bool          `json:"dryRun"`                       // DryRun 数据库空跑特性,开启后不会真正执行数据库操作,部分数据库可能不支持
	DisablePing   bool          `json:"disablePing"`                  // DisablePing 是否禁用自动ping
	MaxIdleConns  int           `json:"maxIdleConns"`                 // MaxIdleConns 最大空闲连接数
	MaxOpenConns  int           `json:"maxOpenConns"`                 // MaxOpenConns 最大连接数
	MaxLifeTime   time.Duration `json:"maxLifeTime"`                  // MaxLifeTime 连接有效期
	MaxIdleTime   time.Duration `json:"maxIdleTime"`                  // MaxIdleTime
	SingularTable bool          `json:"singularTable"`                // SingularTable 是否使用单数表名
	Logger        logger.Option `json:"logger" mapstructure:"logger"` // Logger 日志配置
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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