models

package
v0.0.0-...-011315e Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//ProjectTodoWait 等待处理
	ProjectTodoWait int = iota + 1
	// ProjectTodoWorking 工作中
	ProjectTodoWorking
	// ProjectTodoDone 完成
	ProjectTodoDone
)

Variables

This section is empty.

Functions

func Connect

func Connect(dsn string) (err error)

Connect 链接数据库

func GetPagingParams

func GetPagingParams(c *gin.Context) (page int, size int)

GetPagingParams 获取分页参数

func GetParamsTryInt

func GetParamsTryInt(val string, defaults int) int

GetParamsTryInt 字符串转数字

Types

type FavoriteProjectModel

type FavoriteProjectModel struct {
	Model
	UserID    uint `json:"user_id"`
	ProjectID uint `json:"project_id"`
}

FavoriteProjectModel 收藏的项目

func (*FavoriteProjectModel) TableName

func (f *FavoriteProjectModel) TableName() string

TableName 表名

func (*FavoriteProjectModel) Validator

func (f *FavoriteProjectModel) Validator() (err error)

Validator Validator

type GormDB

type GormDB struct {
	*gorm.DB
}

GormDB 自定义方法

var DB *GormDB = &GormDB{}

DB 全局数据库对象

func (*GormDB) ConnectMysql

func (g *GormDB) ConnectMysql(dsn string) (err error)

ConnectMysql 链接mysql

func (*GormDB) GetObjectOrNotFound

func (g *GormDB) GetObjectOrNotFound(obj interface{}, query interface{}, midd ...Middleware) (err error)

GetObjectOrNotFound 获取某一条数据 gorm first查询接收空条件,在某些情况下会操作到错误到数据

func (*GormDB) GetObjectsOrEmpty

func (g *GormDB) GetObjectsOrEmpty(obj interface{}, query interface{}, args ...Middleware) *Objects

GetObjectsOrEmpty 获取列表 \n 可选参数 middleware models.middleware 接收一个 *gorm.DB 返回 *gorm.DB

type Middleware

type Middleware func(db *gorm.DB) *gorm.DB

Middleware 查询中间操作

type Model

type Model struct {
	ID        uint           `json:"id" gorm:"primarykey"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

Model Model

type ModelType

type ModelType interface {
	//Validator 验证模型
	//常用的非空验证 友好提示
	Validator() (err error)

	//TableName
	//邀请数据模型必须提供tablename
	//gorm依次自动迁移建表
	//查询数据比如join操作可以便捷拼接表名
	TableName() string
}

ModelType 数据库需要实现对应的便捷方法

type Objects

type Objects struct {
	Obj        interface{}
	Model      *gorm.DB
	Pagination *Pagination
	Result     *Result
}

Objects List

func (*Objects) All

func (o *Objects) All() (err error)

All 全部数据

func (*Objects) Paging

func (o *Objects) Paging(page int, size int, args ...Middleware) (err error)

Paging 分页数据

type Page

type Page struct {
	Page int
	URL  string
}

Page 分页

type Pagination

type Pagination struct {
	Page      int    `json:"page"`
	Size      int    `json:"size"`
	Total     int    `json:"total"`
	URLFormat string `json:"-"`
}

Pagination 分页数据

func (*Pagination) Pages

func (p *Pagination) Pages() int

Pages 总页数

func (*Pagination) Range

func (p *Pagination) Range() []Page

Range 生成数组

func (*Pagination) SetURLFormat

func (p *Pagination) SetURLFormat(url string) string

SetURLFormat 设置url

func (*Pagination) URL

func (p *Pagination) URL(page int, size int) string

URL 获取url

type ProjectLogModel

type ProjectLogModel struct {
	Model
	ProjectID    uint   `json:"project_id"`
	Content      string `json:"content"`
	PlusProgress int    `json:"plus_progress"`
}

ProjectLogModel 项目日志

func (*ProjectLogModel) IsToday

func (p *ProjectLogModel) IsToday() bool

IsToday 在今天创建的

func (*ProjectLogModel) TableName

func (p *ProjectLogModel) TableName() string

TableName 表名

func (*ProjectLogModel) Validator

func (p *ProjectLogModel) Validator() (err error)

Validator 验证

type ProjectModel

type ProjectModel struct {
	Model
	UserID             uint              `json:"user_id" gorm:"not null;"`
	Name               string            `json:"name" form:"name" gorm:"NOT NULL"`
	Describe           string            `json:"describe" form:"describe"`
	Start              utils.JSONTime    `json:"start"  form:"start"`
	ExpectEnd          utils.JSONTime    `json:"expect_end" form:"expect_end"`
	ActualDeliveryDate utils.JSONTime    `json:"actual_delivery_date" form:"actual_delivery_date"`
	Progress           int               `json:"progress" form:"progress"`
	Logs               []ProjectLogModel `json:"logs" gorm:"foreignKey:project_id"`
}

ProjectModel 项目模型

func (*ProjectModel) TableName

func (p *ProjectModel) TableName() string

TableName 表名

func (*ProjectModel) TestVal

func (p *ProjectModel) TestVal() string

TestVal 模板测试

func (*ProjectModel) Validator

func (p *ProjectModel) Validator() (err error)

Validator 验证

type ProjectTodoModel

type ProjectTodoModel struct {
	Model
	ProjectID uint           `json:"project_id" gorm:"comment:项目id"`
	UserID    uint           `json:"user_id" gorm:"comment:认领工作的用户"`
	Content   string         `json:"content"`
	Statuc    int            `json:"statuc" gorm:"comment:1-待认领,2-处理中,3-已完成"`
	DoneTime  gorm.DeletedAt `json:"done_time"`
	Done      bool           `json:"done" gorm:"-"`
}

ProjectTodoModel 待处理任务

func (*ProjectTodoModel) TableName

func (p *ProjectTodoModel) TableName() string

TableName 表名

func (*ProjectTodoModel) Validator

func (p *ProjectTodoModel) Validator() (err error)

Validator 验证器

type Result

type Result struct {
	List interface{} `json:"list"`
	*Pagination
}

Result Result

type UserModel

type UserModel struct {
	Model
	Nick     string `json:"nick" form:"nick" gorm:"index;not null;unique"`
	HeadPic  string `json:"head_pic" form:"head_pic"`
	Email    string `json:"email" form:"email" gorm:"index;"`
	Password string `json:"password" gorm:"not null"`
}

UserModel 用户

func (*UserModel) TableName

func (u *UserModel) TableName() string

TableName 表名

func (*UserModel) Validator

func (u *UserModel) Validator() error

Validator 验证

func (*UserModel) VerifyRepeatEmail

func (u *UserModel) VerifyRepeatEmail() error

VerifyRepeatEmail 验证重复邮箱

func (*UserModel) VerifyRepeatNickName

func (u *UserModel) VerifyRepeatNickName() error

VerifyRepeatNickName 验证重复昵称

Jump to

Keyboard shortcuts

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