db

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAnyNil added in v1.0.8

func IsAnyNil(a any) bool

func IsZero added in v1.0.5

func IsZero(value any) bool

func Like added in v1.0.8

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

Like 模糊查询

func OcaclePaginate added in v1.0.8

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

func Offset added in v1.0.8

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

func Paginate added in v1.0.8

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

Paginate 分页

func Unique added in v1.0.8

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

Unique 检查字段是否唯一

func W added in v1.0.8

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

Where 条件查询

Types

type Backup

type Backup struct {
	Db *sql.DB
	// contains filtered or unexported fields
}

func NewDbBackup

func NewDbBackup(db *gorm.DB, path string) (*Backup, error)

创建一个数据库备份对象

func (*Backup) Backup

func (db *Backup) Backup() error

备份数据库

func (*Backup) GetDbName

func (db *Backup) GetDbName() (string, error)

func (*Backup) Restore

func (db *Backup) Restore() error

恢复数据库

type DeleteParam

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

type FirstParam

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

type ListData

type ListData struct {
	Data             any   `json:"data"`
	Total            int32 `json:"total"`      // 总数量
	TotalPage        int32 `json:"total_page"` // 总页数
	Page             int32 `json:"page"`
	PageSize         int32 `json:"page_size"`
	CountUseSubQuery bool  `json:"count_use_sub_query"`
}

type ListParamBase

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

type ListResult added in v1.0.8

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

type Model

type Model[T any] struct {
	Db     *gorm.DB
	Error  error
	Pk     int32
	PkName string
	Model  T
}

func NewModel

func NewModel[T any](db *gorm.DB, model T) *Model[T]

func (*Model[T]) Code

func (m *Model[T]) Code(n int32, field string) (string, error)

生成唯一随机码

func (*Model[T]) Copy

func (m *Model[T]) Copy(param any) *Model[T]

func (*Model[T]) Delete

func (m *Model[T]) Delete(id any) *Model[T]

删除

func (*Model[T]) FindChildren

func (m *Model[T]) FindChildren(pid any, idName, pidName, childrenName, order string) *Model[T]

func (*Model[T]) FindChildrenID

func (m *Model[T]) FindChildrenID(ids *[]int32, pidName string) *Model[T]

func (*Model[T]) List

func (m *Model[T]) List(data *ListData) *Model[T]

查询列表

func (*Model[T]) NotSame

func (m *Model[T]) NotSame(sames *[]Same) *Model[T]

唯一性判断

func (*Model[T]) Number added in v1.0.8

func (m *Model[T]) Number(n int32, field string) (int64, error)

生成唯一数字

func (*Model[T]) NumberToString added in v1.0.8

func (m *Model[T]) NumberToString(n int32, field string) (string, error)

生成唯一数字

func (*Model[T]) Save

func (m *Model[T]) Save() *Model[T]

func (*Model[T]) SetModel

func (m *Model[T]) SetModel(db *gorm.DB) *Model[T]

func (*Model[T]) SetPk

func (m *Model[T]) SetPk(pk int32) *Model[T]

func (*Model[T]) SetPkName

func (m *Model[T]) SetPkName(pkName string) *Model[T]

func (*Model[T]) Update

func (m *Model[T]) Update(field string, value any, containsas []string) *Model[T]

更新

func (*Model[T]) Where

func (m *Model[T]) Where(data []Where) *Model[T]

将 Where 结构体转换为安全的 SQL where 子句和参数

type ModelChildren added in v1.0.4

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 added in v1.0.4

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

type ModelDeletedAt added in v1.0.8

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

type ModelHasChildren added in v1.0.4

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

type ModelID added in v1.0.4

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

type ModelSort added in v1.0.4

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

type ModelState added in v1.0.4

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

type ModelUpdatedAt added in v1.0.4

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

type Same

type Same struct {
	Db      *gorm.DB
	Message string
}

type Sharding added in v1.0.8

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

func NewSharding added in v1.0.8

func NewSharding(gormDB *gorm.DB, baseName string) *Sharding

func (*Sharding) GetMaxPrimaryKeyValue added in v1.0.8

func (s *Sharding) GetMaxPrimaryKeyValue() (maxID int32, err error)

查询当前分表的最大ID

func (*Sharding) GetTable added in v1.0.8

func (s *Sharding) GetTable(model any) (oldTable, newTable string, err error)

func (*Sharding) SetMaxNum added in v1.0.8

func (s *Sharding) SetMaxNum(maxNum int32) *Sharding

func (*Sharding) Tables added in v1.0.8

func (s *Sharding) Tables() ([]Table, error)

type Table added in v1.0.8

type Table struct {
	Name string
	Num  int32
}

type Time

type Time time.Time

func (Time) MarshalJSON

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

func (*Time) Scan

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

func (Time) Time added in v1.0.8

func (t Time) Time() time.Time

func (Time) ToDateString

func (t Time) ToDateString() string

func (Time) ToString

func (t Time) ToString() string

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

更新参数

type Where

type Where struct {
	Name     string // 字段名
	Op       string // 操作符
	Value    any    // 条件值
	Nullable bool   // 是否允许为空值
}

Jump to

Keyboard shortcuts

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