orm

package
v1.1.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoErr         = ErrMsg{2000, "请求成功"}
	NeedInitErr   = ErrMsg{2001, "前往初始化数据库"}
	AuthErr       = ErrMsg{4001, "认证错误"}
	AuthExpireErr = ErrMsg{4002, "token 过期,请刷新token"}
	AuthActionErr = ErrMsg{4003, "权限错误"}
	ParamErr      = ErrMsg{4004, "参数解析失败,请联系管理员"}
	SystemErr     = ErrMsg{5000, "系统错误,请联系管理员"}
	DataEmptyErr  = ErrMsg{5001, "数据为空"}
	TokenCacheErr = ErrMsg{5002, "TOKEN CACHE 错误"}

	ErrParamValidate = errors.New("参数验证失败")
	ErrPaginateParam = errors.New("分页查询参数缺失")
)

Functions

func Create

func Create(db *gorm.DB, cud CUDFunc) (uint, error)

Create 添加

func Delete

func Delete(db *gorm.DB, cud CUDFunc, scopes ...func(db *gorm.DB) *gorm.DB) error

Delete // 删除

func Find

func Find(db *gorm.DB, prf PageResponseFunc, scopes ...func(db *gorm.DB) *gorm.DB) error

Find 不分页

func First

func First(db *gorm.DB, rf ResponseFunc, scopes ...func(db *gorm.DB) *gorm.DB) error

func Pagination

func Pagination(db *gorm.DB, prf PageResponseFunc, pageScope func(db *gorm.DB) *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) (int64, error)

Pagination 分页

func Update

func Update(db *gorm.DB, id uint, cud CUDFunc) error

Update 更新

Types

type CUDFunc

type CUDFunc interface {
	Create(db *gorm.DB) (uint, error)
	Update(db *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) error
	Delete(db *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) error
}

CUDFunc 增改删接口

type ErrMsg

type ErrMsg struct {
	Code int64  `json:"code"`
	Msg  string `json:"message"`
}

ErrMsg

type Model

type Model struct {
	Id        uint   `json:"id" uri:"id" form:"id" param:"id"`
	UpdatedAt string `json:"updatedAt" uri:"updatedAt" form:"updatedAt" param:"updatedAt"`
	CreatedAt string `json:"createdAt" uri:"createdAt" form:"createdAt" param:"createdAt"`
}

Model

type PageResponseFunc

type PageResponseFunc interface {
	Paginate(db *gorm.DB, pageScope func(db *gorm.DB) *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) (int64, error)
	Find(db *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) error
}

PageResponseFunc 分页接口

type Paginate

type Paginate struct {
	Page     int    `json:"page" form:"page"`
	PageSize int    `json:"pageSize" form:"pageSize"`
	OrderBy  string `json:"orderBy" form:"orderBy"`
	Sort     string `json:"sort" form:"sort"`
}

Paginate 验证请求参数

func (*Paginate) PaginateScope

func (req *Paginate) PaginateScope() func(db *gorm.DB) *gorm.DB

PaginateScope 分页 scope

func (*Paginate) Request

func (req *Paginate) Request(ctx interface{}) error

type ReqId

type ReqId struct {
	Id uint `json:"id" uri:"id" form:"id" param:"id"`
}

ReqId 获取id请求参数

func (*ReqId) Request

func (req *ReqId) Request(ctx interface{}) error

type Response

type Response struct {
	Code int64       `json:"code"`
	Msg  string      `json:"message"`
	Data interface{} `json:"data"`
}

Response

type ResponseFunc

type ResponseFunc interface {
	First(db *gorm.DB, scopes ...func(db *gorm.DB) *gorm.DB) error
}

ResponseFunc 单个查询接口

Jump to

Keyboard shortcuts

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