mysqltool

package
v0.0.0-...-93060db Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMySQLFromConfig

func NewMySQLFromConfig(c *Config, opts ...Option) (*gorm.DB, error)

NewMySQLFromConfig 创建gorm mysql DB

func NewMySQLFromConnString

func NewMySQLFromConnString(ds string, opts ...Option) (*gorm.DB, error)

NewMySQLFromConnString 创建gorm mysql DB

func SetMultiDb

func SetMultiDb(db *gorm.DB)

func WithMaxIdleConn

func WithMaxIdleConn()

func WithMaxOpenConn

func WithMaxOpenConn()

Types

type Config

type Config struct {
	Host     string //mysql host
	Port     int    //mysql port
	Username string //mysql user
	Password string //mysql pwd
	DbName   string //db name
	MaxConn  int    //最大连接数 默认200
	IdleConn int    //空闲时连接数 默认20
	LogFile  string `json:",default=log/db"`
}

type IdType

type IdType struct {
	Id        int64      `gorm:"primarykey" json:"id"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt *time.Time `json:"updated_at"`
	IsDelType
}

type IsDelType

type IsDelType struct {
	DeletedAt *time.Time            `json:"deleted_at"`
	IsDeleted soft_delete.DeletedAt `gorm:"type:tinyint(4);softDelete:flag,DeletedAtField:DeletedAt;default:0" json:"is_deleted"`
}

type Option

type Option func()

type Order

type Order struct {
	OrderId string       `gorm:"primarykey;type:varchar(50);" json:"orderId"`
	Amount  int64        `json:"amount"`
	Goods   []OrderGoods `json:"goods"`
}

type OrderGoods

type OrderGoods struct {
	OrderId string `gorm:"primarykey;type:varchar(50);" json:"orderId"`
	SkuId   string `gorm:"primarykey;type:varchar(50);" json:"skuId"`
	Num     int    `json:"num"`
	Price   int64  `json:"price"`
}

Jump to

Keyboard shortcuts

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