mysql

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MulanPSL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogFormatLocalTrace = "%s\n\t[spend:%.3fms] [rows:%v] %s"                   // file, spend, row, sql
	LogFormatLocalWarn  = "(SLOW SQL >= %v) %s\n\t [spend:%.3fms] [rows:%v] %s" // slow_threshold, file, spend, row, sql
	LogFormatLocalError = "%s\n\t%s\n\t%s"                                      // file, err, sql

	LogFormatDevTrace = "[file:%s] [spend:%.3fms] [rows:%v] SQL: %s"                // file, spend, row, sql
	LogFormatDevWarn  = "[threshold:%v] [file:%s] [spend:%.3fms] [rows:%v] SQL: %s" // slow_threshold, file, spend, row, sql
	LogFormatDevError = "[file:%s] [err:%s] SQL: %s"                                // file, err, sql
)

Variables

This section is empty.

Functions

func DefaultNewClient added in v0.1.3

func DefaultNewClient(c *ClientConfig, cc *Config, log logger.Interface) (db *gorm.DB, err error)

Types

type Client

type Client struct {
	Client *gorm.DB
	Cfg    ClientConfig

	CreateClient func(c *ClientConfig, cc *Config, log logger.Interface) (db *gorm.DB, err error)
	// contains filtered or unexported fields
}

func (*Client) CliFlags

func (c *Client) CliFlags(name string) []cli.Flag

func (*Client) Load

func (c *Client) Load(r *Component, name string, cfg *Config, log logger.Interface) (err error)

func (*Client) Ref

func (c *Client) Ref() *Component

type ClientConfig

type ClientConfig struct {
	Master     ConnConfig   `json:"master"        yaml:"master"`
	Slave      []ConnConfig `json:"slave"         yaml:"slave"`
	MaxOpenNum int          `json:"max_open_num"  yaml:"max_open_num"`
	MaxIdleNum int          `json:"max_idle_num"  yaml:"max_idle_num"`
}

type Component

type Component struct {
	DSNPrint bool
	Cfg      Config
	Clts     map[string]*Client
	Log      Logger
	// contains filtered or unexported fields
}

func (*Component) CliFlags

func (c *Component) CliFlags() []cli.Flag

func (*Component) Close

func (c *Component) Close(_ gsfLogger.Interface, _ gsf.Config) error

func (*Component) Init

func (c *Component) Init(log gsfLogger.Interface, cfg gsf.Config) error

func (*Component) Prefix added in v0.1.3

func (c *Component) Prefix() string

func (*Component) Run

func (*Component) SetPrefix added in v0.1.3

func (c *Component) SetPrefix(v string) bool

type Config

type Config struct {
	MaxLifeTime   int `json:"max_req_time"    yaml:"max_req_time"`
	MaxIdleTime   int `json:"max_idle_time"   yaml:"max_idle_time"`
	SlowThreshold int `json:"slow_threshold"  yaml:"slow_threshold"`
}

type ConnConfig

type ConnConfig struct {
	Host     string `json:"host"      yaml:"host"`
	UserName string `json:"user"      yaml:"user"`
	Password string `json:"password"  yaml:"password"`
	Database string `json:"db"        yaml:"db"`
	Options  string `json:"options"   yaml:"options"`
	// contains filtered or unexported fields
}

func (*ConnConfig) GetConnectDSN

func (c *ConnConfig) GetConnectDSN() string

func (*ConnConfig) GetPrintDSN

func (c *ConnConfig) GetPrintDSN() string

func (*ConnConfig) ParserDSN

func (c *ConnConfig) ParserDSN(val string) error

type Logger

type Logger struct {
	SlowThreshold time.Duration

	LogFmtTrace, LogErrFmt, LogWarnFmt string
	// contains filtered or unexported fields
}

func (*Logger) Error

func (l *Logger) Error(_ context.Context, msg string, data ...interface{})

func (*Logger) Info

func (l *Logger) Info(_ context.Context, msg string, data ...interface{})

func (*Logger) LogMode

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

func (*Logger) SetLogger

func (l *Logger) SetLogger(log gsfLogger.Interface)

func (*Logger) Trace

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

func (*Logger) Warn

func (l *Logger) Warn(_ context.Context, msg string, data ...interface{})

Jump to

Keyboard shortcuts

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