fire

package
v2.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package fire /**/ 对 gorm.DB 的补充封装,实现更爽快得使用。属于基础层服务代码。

Index

Constants

View Source
const ColumnAll = "*"
View Source
const DefaultPageSize = 20

Variables

This section is empty.

Functions

func AsLabel added in v2.1.5

func AsLabel(column, asColumn string) (lab string)

func Camel2Case added in v2.1.2

func Camel2Case(name string) string

func CountLabel added in v2.1.5

func CountLabel(column ...string) (lab string)

func DistinctOnLabel added in v2.1.5

func DistinctOnLabel(column ...string) (lab string)

func FormatColumn

func FormatColumn(column ...string) (res string)

func If

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

func SetFormatColumnType added in v2.1.5

func SetFormatColumnType(v FormatColumnType)

func UnnestLabel added in v2.1.5

func UnnestLabel(column ...string) (lab string)

func UpdateArithmetic

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

UpdateArithmetic field = field ArithmeticType Number # field = field + 1

func WhereCompare added in v2.1.6

func WhereCompare(column string, value interface{}, compare ...CompareType) func(*gorm.DB) *gorm.DB

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 url.Values, db *Fire) *Fire

AllowParams allow params

func (*Allow) AllowSort

func (a *Allow) AllowSort(sort url.Values, db *Fire) *Fire

AllowSort allow sort

type ArithmeticType

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

type Column added in v2.1.5

type Column struct {
	Table  string
	Column string
}

func (*Column) String added in v2.1.5

func (c *Column) String() string

type CompareType

type CompareType string
const (
	CompareEqual        CompareType = "="
	CompareGreaterEqual CompareType = ">="
	CompareGreater      CompareType = ">"
	CompareSmallerEqual CompareType = "<="
	CompareSmaller      CompareType = "<"
)

type Diary added in v2.1.5

type Diary struct {
	Sql []string
}

func (*Diary) Error added in v2.1.5

func (n *Diary) Error(c context.Context, sql string, a ...interface{})

func (*Diary) Info added in v2.1.5

func (n *Diary) Info(c context.Context, sql string, a ...interface{})

func (*Diary) LastSql added in v2.1.5

func (n *Diary) LastSql(position ...int) string

func (*Diary) LogMode added in v2.1.5

func (n *Diary) LogMode(logger.LogLevel) logger.Interface

func (*Diary) Trace added in v2.1.5

func (n *Diary) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

func (*Diary) Warn added in v2.1.5

func (n *Diary) Warn(c context.Context, sql string, a ...interface{})

type Fire added in v2.1.0

type Fire struct {
	*gorm.DB
}

func NewInstance

func NewInstance(db *gorm.DB) *Fire

func (*Fire) Allow added in v2.1.0

func (d *Fire) Allow(params url.Values, allow Allow) *Fire

func (*Fire) Close added in v2.1.0

func (d *Fire) Close() (err error)

func (*Fire) CrudAll added in v2.1.0

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

func (*Fire) CrudAllPage added in v2.1.0

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

func (*Fire) CrudAllPagePreloadAll added in v2.1.0

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

func (*Fire) CrudAllPagePreloadJoin added in v2.1.0

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

func (*Fire) CrudAllPreloadAll added in v2.1.0

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

func (*Fire) CrudAllPreloadJoin added in v2.1.0

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

func (*Fire) CrudCount added in v2.1.0

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

func (*Fire) CrudCreate added in v2.1.0

func (d *Fire) CrudCreate(model interface{}, batchSize ...int) (err error)

CrudCreate model support Array,Slice,Struct every struct support tag `gormCreate` validator.Struct()

func (*Fire) CrudDelete added in v2.1.0

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

func (*Fire) CrudOne added in v2.1.0

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

func (*Fire) CrudOnePreloadAll added in v2.1.0

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

func (*Fire) CrudOnePreloadJoin added in v2.1.0

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

func (*Fire) CrudSum added in v2.1.0

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

func (*Fire) CrudUpdate added in v2.1.0

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

CrudUpdate 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 (*Fire) CrudUpdateByPrimaryKey added in v2.1.5

func (d *Fire) CrudUpdateByPrimaryKey(model interface{}, updates ...interface{}) (err error)

CrudUpdateByPrimaryKey Make sure that all primary keys are not zero when updating

func (*Fire) IsExists added in v2.1.0

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

func (*Fire) ModelWhere added in v2.1.5

func (d *Fire) ModelWhere(model interface{}) *Fire

WhereIn column IN(?) column NOT IN(?)

func (*Fire) OrderByColumn added in v2.1.0

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

func (*Fire) PreloadAll added in v2.1.0

func (d *Fire) PreloadAll() *Fire

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

func (*Fire) PreloadJoin added in v2.1.0

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

PreloadJoin 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 (*Fire) SumLabel added in v2.1.5

func (d *Fire) SumLabel(column ...string) (lab string)

func (*Fire) WhereCompare added in v2.1.0

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

WhereCompare column CompareEqual ? # column = ?

func (*Fire) WhereIn added in v2.1.0

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

WhereIn column IN(?) column NOT IN(?)

func (*Fire) WhereLike added in v2.1.0

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

WhereLike column LIKE %?%

func (*Fire) WhereRange added in v2.1.0

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

WhereRange column >= start ANd column <= end

type FormatColumnType added in v2.1.5

type FormatColumnType string
const (
	FormatColumnBackQuote      FormatColumnType = "`"
	FormatColumnQuotationMarks FormatColumnType = `"`
)

type M

type M map[string]interface{}

type OrderType

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

type Page

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

func (*Page) DefaultSize added in v2.1.3

func (p *Page) DefaultSize(pageSize int) Page

func (*Page) GetOffset

func (p *Page) GetOffset() int

func (*Page) SetSize added in v2.1.3

func (p *Page) SetSize(pageSize int) *Page

type PageResult

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

PageResult 分页结果

func (*PageResult) Init

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

func (*PageResult) SetData added in v2.1.5

func (p *PageResult) SetData(d interface{})

type SinglePageResult added in v2.1.5

type SinglePageResult struct {
	Data interface{} `json:"data"`
}

SinglePageResult 单页结果

type TimeFields1Model added in v2.1.5

type TimeFields1Model struct {
	// 13位毫秒时间戳
	CreatedAt int64 `gorm:"column:created_at;autoCreateTime:milli;type:bigint(13);unsigned;comment:创建时间;<-:create" json:"createdAt"`
}

func (*TimeFields1Model) BeforeCreate added in v2.1.5

func (t *TimeFields1Model) BeforeCreate(tx *gorm.DB) (err error)

type TimeFields2Model added in v2.1.5

type TimeFields2Model struct {
	TimeFields1Model
	// 13位毫秒时间戳,兼容用户一秒内多次点击修改
	UpdatedAt int64 `gorm:"column:updated_at;autoUpdateTime:milli;type:bigint(13);unsigned;comment:修改时间;<-" json:"updatedAt"`
}

type TimeFields3Model added in v2.1.5

type TimeFields3Model struct {
	TimeFields2Model
	// 软删除,默认为0,删除时设置当前10位秒数时间戳
	DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:bigint(13);unsigned;comment:删除时间;<-:false" json:"deletedAt"`
}

Jump to

Keyboard shortcuts

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