fire

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

* * @Author: TheLife * @Date: 2021/5/26 下午11:21

* * @Author: TheLife * @Date: 2021/5/27 下午5:08

* * @Author: TheLife * @Date: 2021/5/26 下午5:01

* * @Author: TheLife * @Date: 2021/6/23 下午9:37

* * @Author: TheLife * @Date: 2021/5/27 下午4:34

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatColumn

func FormatColumn(column string) (res string)

格式化列

func If

func If(isA bool, a, b interface{}) interface{}

func UpdateArithmetic

func UpdateArithmetic(column string, value interface{}, art ArithmeticType) (m map[string]interface{})

field = field ArithmeticType Number # field = field + 1

Types

type Allow

type Allow struct {
	// where
	Where []string
	Range []string
	In    []string
	Like  []string

	// order
	Sorts []string
}

func (*Allow) AllowParams

func (a *Allow) AllowParams(params Params, db *DbUtils) *DbUtils

allowParams

func (*Allow) AllowSort

func (a *Allow) AllowSort(sort Sort, db *DbUtils) *DbUtils

allowSort

type ArithmeticType

type ArithmeticType string

=== update ===

const (
	ArithmeticIncrease ArithmeticType = "+"
	ArithmeticReduce   ArithmeticType = "-"
	ArithmeticMultiply ArithmeticType = "*"
	ArithmeticExcept   ArithmeticType = "/"
)

type CompareType

type CompareType string
const (
	CompareEqual      CompareType = "="
	CompareAboutEqual CompareType = ">="
	CompareAbout      CompareType = ">"
	CompareLessEqual  CompareType = "<="
	CompareLess       CompareType = "<"
)

type DbUtils

type DbUtils struct {
	*gorm.DB
}

func NewInstance

func NewInstance(db *gorm.DB) *DbUtils

func (*DbUtils) Allow

func (d *DbUtils) Allow(param Param, allow Allow) *DbUtils

allow

func (*DbUtils) CrudAll

func (d *DbUtils) CrudAll(model interface{}, callListData interface{}) (err error)

func (*DbUtils) CrudAllPage

func (d *DbUtils) CrudAllPage(model interface{}, callListData interface{}, page ...Page) (pageResult PageResult, err error)

func (*DbUtils) CrudAllPagePreloadAll

func (d *DbUtils) CrudAllPagePreloadAll(model interface{}, callListData interface{}, page ...Page) (pageResult PageResult, err error)

func (*DbUtils) CrudAllPagePreloadJoin

func (d *DbUtils) CrudAllPagePreloadJoin(model interface{}, callListData interface{}, page ...Page) (pageResult PageResult, err error)

func (*DbUtils) CrudAllPreloadAll

func (d *DbUtils) CrudAllPreloadAll(model interface{}, callListData interface{}) (err error)

func (*DbUtils) CrudAllPreloadJoin

func (d *DbUtils) CrudAllPreloadJoin(model interface{}, callListData interface{}) (err error)

func (*DbUtils) CrudCount

func (d *DbUtils) CrudCount(model interface{}) (count int64, err error)

func (*DbUtils) CrudDelete

func (d *DbUtils) CrudDelete(model interface{}) (err error)

func (*DbUtils) CrudOne

func (d *DbUtils) CrudOne(model interface{}, callData interface{}) (err error)

func (*DbUtils) CrudOnePreloadAll

func (d *DbUtils) CrudOnePreloadAll(model interface{}, callData interface{}) (err error)

func (*DbUtils) CrudOnePreloadJoin

func (d *DbUtils) CrudOnePreloadJoin(model interface{}, callData interface{}) (err error)

func (*DbUtils) CrudSum

func (d *DbUtils) CrudSum(model interface{}, column string) (sum float32, err error)

func (*DbUtils) CrudUpdate

func (d *DbUtils) CrudUpdate(model interface{}, updates ...interface{}) (err error)

updates support M(or map[string]interface{}) and struct support gorm.Db.Select() and gorm.Db.Omit() TODO: struct only update non-zero fields

func (*DbUtils) IsExists

func (d *DbUtils) IsExists(model interface{}) bool

func (*DbUtils) OrderByColumn

func (d *DbUtils) OrderByColumn(column string, order OrderType, many ...bool) *DbUtils

func (*DbUtils) PreloadAll

func (d *DbUtils) PreloadAll() *DbUtils

=== SELECT === TODO:Multiple SQL, gorm bonding data, so query conditions other than the main table are not supported

func (*DbUtils) PreloadJoin

func (d *DbUtils) PreloadJoin(model interface{}) *DbUtils

TODO:Single SQL, mysql bonding data, so the conditions of all query tables are supported. use Join you need to pay attention to performance

func (*DbUtils) WhereCompare

func (d *DbUtils) WhereCompare(column string, value interface{}, compare ...CompareType) *DbUtils

column CompareEqual ? # column = ?

func (*DbUtils) WhereIn

func (d *DbUtils) WhereIn(column string, value interface{}, isNot ...bool) *DbUtils

column IN(?) column NOT IN(?)

func (*DbUtils) WhereLike

func (d *DbUtils) WhereLike(column string, value interface{}) *DbUtils

column LIKE %?%

func (*DbUtils) WhereRange

func (d *DbUtils) WhereRange(column string, start interface{}, end interface{}) *DbUtils

column >= start ANd column <= end

type M

type M map[string]interface{}

type OrderType

type OrderType string

=== order ===

const (
	OrderAsc  OrderType = "asc"
	OrderDesc OrderType = "desc"
)

type Page

type Page struct {
	Current  int `json:"current" form:"current"`
	PageSize int `json:"page_size" form:"page_size"`
}

func (*Page) GetOffset

func (p *Page) GetOffset() int

type PageParam

type PageParam struct {
	Page
	Param
}

分页参数

type PageResult

type PageResult struct {
	Page
	Total int64 `json:"total"`
}

分页结果

func (*PageResult) Init

func (p *PageResult) Init(page ...Page)

type Param

type Param struct {
	Params Params `form:"params" json:"params"`
	Sort   Sort   `form:"sort" json:"sort" binding:"omitempty,eq=1,dive,keys,required,endkeys,eq=ascend|eq=descend"`
}

筛选、排序参数

type Params

type Params map[string]interface{}

type Sort

type Sort map[string]string

type TimeFieldsModel

type TimeFieldsModel struct {
	// 13位毫秒时间戳
	CreatedAt int64 `gorm:"autoCreateTime:milli;type:bigint(13);unsigned;comment:创建时间" json:"created_at"`
	// 13位毫秒时间戳,兼容用户一秒内多次点击
	UpdatedAt int64 `gorm:"autoUpdateTime:milli;type:bigint(13);unsigned;comment:修改时间" json:"updated_at"`
	// 软删除,默认为0,删除时设置当前10位秒数时间戳
	DeletedAt soft_delete.DeletedAt `gorm:"type:bigint(13);unsigned;comment:删除时间" json:"deleted_at"`
}

Jump to

Keyboard shortcuts

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