db

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNilOrZero

func IsNilOrZero(v any) bool

IsNilOrZero 判断值是否为 nil 或零值

func IsZero

func IsZero(v any) bool

IsZero 判断值是否为零值

func Like

func Like(where string, value any, options ...string) func(db *gorm.DB) *gorm.DB

Like 模糊查询

func Offset

func Offset(offset, limit *int32, maxLimit ...int32) func(db *gorm.DB) *gorm.DB

func OpenDBWithTimeout

func OpenDBWithTimeout(dialector gorm.Dialector, timeout time.Duration) (*gorm.DB, error)

控制数据库连接超时

func OraclePaginate

func OraclePaginate(db *gorm.DB, data any, page, pageSize *int32, maxPageSize ...int32) error

func Paginate

func Paginate(page, pageSize *int32, maxPageSize ...int32) func(db *gorm.DB) *gorm.DB

Paginate 分页

func Unique

func Unique(DB *gorm.DB, primaryField string, primaryKey any, message string) func(db *gorm.DB) *gorm.DB

Unique 检查字段是否唯一

func Where

func Where(where string, value any) func(db *gorm.DB) *gorm.DB

Where 条件查询

Types

type DeleteParam

type DeleteParam struct {
	IDS []int32 `json:"id" validate:"required:主键值必须"`
}

type FirstParam

type FirstParam struct {
	ID int32 `form:"id" validate:"required:主键值必须"`
}

type ListParamBase

type ListParamBase struct {
	Page     int32  `form:"page"`
	PageSize int32  `form:"page_size"`
	Order    string `form:"order"`
}

type ListResult

type ListResult struct {
	Data     any   `json:"data"`
	Total    int64 `json:"total"`
	Page     int32 `json:"page"`
	PageSize int32 `json:"page_size"`
}

type ModelChildren

type ModelChildren[T any] struct {
	PID      int32 `gorm:"column:pid;type:bigint;default:0;comment:父级id;index" json:"pid"`
	Level    int32 `gorm:"column:level;type:int;default:1;comment:层级;index" json:"level"`
	Children []T   `gorm:"-:migration;foreignKey:pid;references:id" json:"children"`
}

type ModelCreatedAt

type ModelCreatedAt struct {
	CreatedAt Time `gorm:"column:created_at;autoCreateTime:milli;comment:创建时间" json:"created_at"`
}

type ModelDeletedAt

type ModelDeletedAt struct {
	Deleted Time `gorm:"column:deleted;comment:删除时间" json:"deleted"`
}

type ModelHasChildren

type ModelHasChildren struct {
	HasChildren bool `gorm:"-:all;default:false" json:"hasChildren"`
}

type ModelID

type ModelID struct {
	ID int32 `gorm:"column:id;primaryKey;autoIncrement;comment:ID" json:"id"`
}

type ModelSort

type ModelSort struct {
	Sort int32 `gorm:"column:sort;type:bigint;default:100;comment:排序;index" json:"sort"`
}

type ModelState

type ModelState struct {
	State int32 `gorm:"column:state;type:int;default:1;comment:状态:1-开启,2-关闭;index" json:"state"`
}

type ModelUpdatedAt

type ModelUpdatedAt struct {
	UpdatedAt Time `gorm:"column:updated_at;autoUpdateTime:milli;comment:更新时间" json:"updated_at"`
}

type Time

type Time time.Time

func (Time) Format

func (t Time) Format(layout string) string

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) Scan

func (t *Time) Scan(v any) error

func (Time) Time

func (t Time) Time() time.Time

func (Time) Value

func (t Time) Value() (driver.Value, error)

type UpdateParam

type UpdateParam struct {
	ID    int32  `json:"id" validate:"required:主键值必须"`
	Field string `json:"field" validate:"required:字段名必须"`
	Value any    `json:"value"`
}

更新参数

Jump to

Keyboard shortcuts

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