mysql

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConstMysqlUtf8Charset          = "utf8"
	ConstMysqlUtf8mb4Charset       = "utf8mb4"
	ConstDbConnectTimeoutSec       = 10
	ConstHealthCheckStopTimeoutSec = 5
	ConstSlowQueryTimeThreshold    = 2000 // 毫秒
	ConstExecBatchDefaultSize      = 50   // 一次执行批量任务最大多少
	ConstMysqlDefaultDbName        = "test_db"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseModel

type BaseModel struct {
	ID int64 `gorm:"primary_key;column:id" json:"id,omitempty" yaml:"id,omitempty" swaggerignore:"true"`
	DefaultTimeField
}

type Client

type Client struct {
	Object *gorm.DB
	// contains filtered or unexported fields
}

func NewMysqlClient

func NewMysqlClient(conf *ClientConf) *Client

func (*Client) Close

func (c *Client) Close()

Close 这里优化了关闭顺序,优先健康监测关闭,要不然关闭出现监测失败 指针表示当前对象地址,没有指针表示数据副本是一个copy

func (*Client) Connect

func (c *Client) Connect() bool

func (*Client) CreateDatabase

func (c *Client) CreateDatabase() bool

func (*Client) GetCustomSession

func (c *Client) GetCustomSession(val interface{}, opts *gorm.Session) *gorm.DB

func (*Client) GetPrepareStmtSession

func (c *Client) GetPrepareStmtSession(val interface{}) *gorm.DB

func (*Client) GetSession

func (c *Client) GetSession(val interface{}) *gorm.DB

func (*Client) GetSkipTransactionSession

func (c *Client) GetSkipTransactionSession(val interface{}) *gorm.DB

func (*Client) HealthCheck

func (c *Client) HealthCheck() error

type ClientConf

type ClientConf struct {
	Address            string `json:"address" yaml:"address"`
	Port               uint16 `json:"port" yaml:"port"`
	ReadTimeout        uint32 `json:"readTimeout,omitempty" yaml:"readTimeout,omitempty"`
	WriteTimeout       uint32 `json:"writeTimeout,omitempty" yaml:"writeTimeout,omitempty"`
	Username           string `json:"username" yaml:"username"`
	Password           string `json:"password" yaml:"password"`
	DB                 string `json:"db" yaml:"db"`
	Charset            string `json:"charset" yaml:"charset"`
	MaxIdle            int    `json:"maxIdle,omitempty" yaml:"maxIdle,omitempty"`
	MaxOpen            int    `json:"maxOpen,omitempty" yaml:"maxOpen,omitempty"`
	SlowQueryThreshold uint32 `json:"slowQueryThreshold,omitempty" yaml:"slowQueryThreshold,omitempty"`
	ExecBatchSize      uint16 `json:"execBatchSize,omitempty" yaml:"execBatchSize,omitempty"`
}

type DefaultTimeField

type DefaultTimeField struct {
	CreatedAt *time.Time `gorm:"column:created_at" json:"createdAt,omitempty" yaml:"createdAt,omitempty" swaggerignore:"true"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updatedAt,omitempty" yaml:"updatedAt,omitempty" swaggerignore:"true"`
}

Jump to

Keyboard shortcuts

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