mysql

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: MIT Imports: 16 Imported by: 0

README

gsf-mysql

db config json

component

{
  "max_req_time" : 3,
  "max_idle_time" : 3,
  "slow_threshold" : 300
}

client

{
  "master": {
    "host": "127.0.0.1:9800",
    "user": "root",
    "password": "root",
    "db": "test",
    "options": ""
  },
  "slave": [
    {
      "host": "127.0.0.1:9800",
      "user": "root",
      "password": "root",
      "db": "test",
      "options": ""
    }
  ]
}

命令行参数

   --mysql-req-time value               mysql request timeout (default: 0)
   --mysql-idle-time value             mysql idle connect timeout (default: 0)
   --mysql-threshold value             mysql slow sql threshold (default: 0)
   --mysql-{{key}}-open-limit value    mysql({{key}}) max open limit (default: 0)
   --mysql-{{key}}-idle-limit value    mysql({{key}}) idle open limit (default: 0)
   --mysql-{{key}}-dsn value           mysql({{key}}) DSN (format: {{user_name}}:{{password}}@tcp({{host}}:{{port}})/{{db_name}}?{{connect_options}})

资料

gorm 链接字符串

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateClient = defaultNewClient

Functions

This section is empty.

Types

type Client added in v0.3.0

type Client struct {
	Client *gorm.DB
	Cfg    ClientConfig
}

func (*Client) CliFlags added in v0.3.0

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

func (*Client) Load added in v0.3.0

func (c *Client) Load(name string, cfg *ComponentConfig, log *Logger) (err error)

type ClientConfig added in v0.3.0

type ClientConfig struct {
	Master     ConnectConfig   `json:"master"        yaml:"master"`
	Slave      []ConnectConfig `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      ComponentConfig
	Clts     map[string]*Client
	// contains filtered or unexported fields
}

func (*Component) CliFlags

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

func (*Component) Close

func (c *Component) Close() error

func (*Component) Init added in v0.0.6

func (c *Component) Init(l glogger.Interface, cfg *gsf.AppConfig, _ *cli.Context) error

func (*Component) LoadOne added in v0.3.0

func (c *Component) LoadOne(name string) (err error)

func (*Component) Run

func (c *Component) Run() error

func (*Component) SetLogLevel

func (c *Component) SetLogLevel(v int)

type ComponentConfig added in v0.3.0

type ComponentConfig 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 ConnectConfig added in v0.3.0

type ConnectConfig 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"`
}

func (*ConnectConfig) GetConnectDSN added in v0.3.0

func (c *ConnectConfig) GetConnectDSN() string

func (*ConnectConfig) GetPrintDSN added in v0.3.0

func (c *ConnectConfig) GetPrintDSN() string

func (*ConnectConfig) ParserDSN added in v0.3.0

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

type Logger

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

func (*Logger) Error

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

func (*Logger) Info

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

func (*Logger) LogMode

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

func (*Logger) SetLogger added in v0.0.6

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

func (*Logger) Trace

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

func (*Logger) Warn

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

Jump to

Keyboard shortcuts

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