gorm

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Mysql    = "mysql"
	Postgres = "postgres"
)
View Source
const (
	GoDandelionConnChange = "go_dandelion_conn_change"
)

Variables

This section is empty.

Functions

func NewConnection

func NewConnection(config *Config) *gorm.DB

Types

type AppChangeFunc

type AppChangeFunc func(appKey string, changeType ChangeType) (err error)

AppChangeFunc 数据连接变更监听触发方法

type AppConfig

type AppConfig struct {
	AppKey   string
	DBMaster *Master
	DBSlave  []*Slave
}

type AppConfigFunc

type AppConfigFunc func(appKey ...string) (apps []AppConfig, err error)

AppConfigFunc 用于获取需要初始化的应用库 初始化时,不会传递参数。应用数据库变更时, 会传递 appKey

type AppDB

type AppDB struct {
	// contains filtered or unexported fields
}

func InitAppDB

func InitAppDB(configFunc AppConfigFunc, changeFunc AppChangeFunc, redis *redigo.Client) *AppDB

func (*AppDB) Connection

func (client *AppDB) Connection(appKey string) error

func (*AppDB) GetDB

func (client *AppDB) GetDB(appKey string) *gorm.DB

func (*AppDB) Listener

func (client *AppDB) Listener()

Listener 数据库连接变更监听

type AppDBMessage

type AppDBMessage struct {
	AppKey     string
	ChangeType ChangeType
}

func ParseChangeData

func ParseChangeData(msg string) AppDBMessage

ParseChangeData

type ChangeType

type ChangeType int
const (
	Created ChangeType = iota + 1
	Updated
	Deleted
)

type Config

type Config struct {
	DBType        string        `json:"db_type"`
	MaxOpenConn   int           `json:"max_open_conn"`
	MaxIdleConn   int           `json:"max_idle_conn"`
	MaxLifeTime   int           `json:"max_life_time"`
	MaxIdleTime   int           `json:"max_idle_time"`
	Level         int           `json:"level"`
	SlowThreshold time.Duration `json:"slow_threshold"`
	Master        *Master       `json:"master"`
	Slaves        []*Slave      `json:"slaves"`
}

type Logger

type Logger struct {
	Level                     glogger.LogLevel
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
}

func (*Logger) Error

func (logger *Logger) Error(ctx context.Context, s string, i ...interface{})

func (*Logger) Info

func (logger *Logger) Info(ctx context.Context, s string, i ...interface{})

func (*Logger) LogMode

func (logger *Logger) LogMode(level glogger.LogLevel) glogger.Interface

func (*Logger) Trace

func (logger *Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*Logger) Warn

func (logger *Logger) Warn(ctx context.Context, s string, i ...interface{})

type Master

type Master struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Host     string `json:"host"`
	Port     string `json:"port"`
	Database string `json:"database"`
}

type Slave

type Slave struct {
	User     string `json:"user"`
	Password string `json:"password"`
	Host     string `json:"host"`
	Port     string `json:"port"`
	Database string `json:"database"`
}

Jump to

Keyboard shortcuts

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