Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPagingParams ¶
GetPagingParams 获取分页参数
Types ¶
type Controller ¶
type Controller interface { // add update 验证 Validator() error //添加数据生成uuid SetCode() error //添加数据绑定用户id SetUser(c *gin.Context, data interface{}) error // 表名 TableName() string // 自身实例 用于found one Object() interface{} // 自身实例 用于found list Objects() interface{} // 以下三个方法用于辅助默认方法实现curd,过于复杂的直接override // Where 搜索条件 // Search(db *gorm.DB, key string) *gorm.DB // 查询的补充条件 Joins(db *gorm.DB) *gorm.DB // 处理列表返回结果 Result(data interface{}) interface{} }
Controller ModelInterface
type GormDB ¶
GormDB 自定义方法
func (*GormDB) ConnectMysql ¶
ConnectMysql 链接mysql
func (*GormDB) GetObjectOrNotFound ¶
func (g *GormDB) GetObjectOrNotFound(obj interface{}, query map[string]interface{}, midd ...Middleware) (err error)
GetObjectOrNotFound 获取某一条数据 gorm 查询接收空条件,在某些情况下会操作到错误到数据
func (*GormDB) GetObjectsOrEmpty ¶
func (g *GormDB) GetObjectsOrEmpty(obj interface{}, query interface{}, args ...Middleware) *Objects
GetObjectsOrEmpty 获取列表 \n 可选参数 middleware models.middleware 接收一个 *gorm.DB 返回 *gorm.DB
type Model ¶
type Model struct { ID uint `json:"id" gorm:"primary_key"` Code string `json:"code" gorm:"primary_key;index;unique;not null"` // CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"` }
Model 空方法用户数据模型继承方法
type ObjResult ¶
type ObjResult struct { *Pagination List interface{} `json:"list"` }
ObjResult Result
func (*ObjResult) MarshalJSON ¶
MarshalJSON MarshalJSON
type Objects ¶
type Objects struct { Obj interface{} Model *gorm.DB Pagination *Pagination Result *ObjResult }
Objects List
type Pagination ¶
type Pagination struct { Page int `json:"page"` Size int `json:"size"` Total int `json:"total"` URLFormat string `json:"-"` }
Pagination 分页数据
func (*Pagination) SetURLFormat ¶
func (p *Pagination) SetURLFormat(url string) string
SetURLFormat 设置url
Click to show internal directories.
Click to hide internal directories.