database

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDBClient

func NewDBClient(conf Conf) *gorm.DB

NewDBClient 创建GORM数据库连接池

func NewDBClientSetWithProfile

func NewDBClientSetWithProfile(profile types.Profile, cfgset []Conf) map[string]*gorm.DB

func NewDBClientWithProfile

func NewDBClientWithProfile(profile types.Profile, conf Conf) *gorm.DB

Types

type Conf

type Conf struct {
	Name                      string `yaml:"name"`
	Dsn                       string `yaml:"dsn"`
	MaxOpenConn               int    `yaml:"maxOpenConn"`
	MaxIdleConn               int    `yaml:"maxIdleConn"`
	IgnoreRecordNotFoundError bool   `yaml:"ignoreRecordNotFoundError"`
	LogLevel                  int    `yaml:"logLevel"`
}

Conf 数据库相关配置

type Model

type Model struct {
	ID        uint64     `gorm:"primaryKey"`
	CreatedAt types.Time `gorm:"index:idx_ctime"`
	UpdatedAt types.Time
}

Model a basic GoLang struct which includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt It may be embedded into your model or you may build your own model without it

type User struct {
  gorm.Model
}

func (*Model) BeforeCreate

func (o *Model) BeforeCreate(tx *gorm.DB) error

func (*Model) BeforeUpdate

func (o *Model) BeforeUpdate(tx *gorm.DB) (err error)

type Page

type Page struct {
	PageNum   int         `json:"pageNum"`   // 页码
	PageSize  int         `json:"pageSize"`  // 分页大小
	Total     int         `json:"total"`     // 数据总量
	PageCount int         `json:"pageCount"` // 分页数量
	Result    interface{} `json:"result"`    // 分页大小
}

Page 分页模型

func (*Page) Execute

func (p *Page) Execute(db *gorm.DB, result interface{}) error

Execute 执行分页查询

func (*Page) GetLimit

func (p *Page) GetLimit() int

func (*Page) GetOffset

func (p *Page) GetOffset() int

GetOffset 获取分页偏移量

type PageQuery

type PageQuery struct {
	PageNum  int `json:"pageNum" form:"pageNum" binding:"required,min=1" default:"1"`             // 页码
	PageSize int `json:"pageSize" form:"pageSize" binding:"required,min=1,max=500" default:"100"` // 分页大小
}

Jump to

Keyboard shortcuts

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