model

package
v0.0.0-...-1369677 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtFields

func FmtFields(tableName string, fields ...string) []string

FmtFields 格式化数据字段

func GetTimestamp

func GetTimestamp(t time.Time, tt schema.TimeType) (ts int64)

GetTimestamp 获取时间类型对应的当前时间戳

func IsRecordNotFound

func IsRecordNotFound(err error) bool

IsRecordNotFound 判断记录是否被找到

Types

type BaseModel

type BaseModel struct {
	Ctx context.Context
	DB  *gorm.DB
	logging.Logger
}

BaseModel 基础模型

func NewBaseModel

func NewBaseModel(ctx context.Context, db *gorm.DB) *BaseModel

NewBaseModel 新建基础模型

func (*BaseModel) CountByCondition

func (m *BaseModel) CountByCondition(data schema.Tabler, condition func(*gorm.DB) *gorm.DB) (int64, error)

CountByCondition 通过动态条件计数数据信息

func (*BaseModel) DeleteByCondition

func (m *BaseModel) DeleteByCondition(data schema.Tabler, condition func(*gorm.DB) *gorm.DB) error

DeleteByCondition 通过动态条件删除数据信息

func (*BaseModel) ParseUpdateMap

func (m *BaseModel) ParseUpdateMap(data interface{}, omits, selects []string, notIgnores ...string) (map[string]interface{}, error)

ParseUpdateMap 解析模型数据获取对应的更新map,更新时间字段会自动跟踪,参数

data 须为模型数据结构体或其所对应指针
omits 不更新的字段列表,只在selects长度为0时生效
selects 指定更新的字段列表,长度为0时,生成的更新map取模型数据非零值并忽略主键和创建时间字段
notIgnores 不忽略的字段列表,只在selects长度为0时生效,与omits冲突时,以omits为准

func (*BaseModel) PluckInt64s

func (m *BaseModel) PluckInt64s(data schema.Tabler, column string, condition func(*gorm.DB) *gorm.DB) ([]int64, error)

PluckInt64s 通过动态条件查找单个列并将结果扫描到int64切片中

func (*BaseModel) PluckStrings

func (m *BaseModel) PluckStrings(data schema.Tabler, column string, condition func(*gorm.DB) *gorm.DB) ([]string, error)

PluckStrings 通过动态条件查找单个列并将结果扫描到string切片中

func (*BaseModel) Update

func (m *BaseModel) Update(data IdGetter, selects []string) error

Update 通过id更新数据信息

func (*BaseModel) UpdateByCondition

func (m *BaseModel) UpdateByCondition(data schema.Tabler, condition func(*gorm.DB) *gorm.DB) error

UpdateByCondition 通过动态条件更新数据信息

func (*BaseModel) UpdateWithMapByCondition

func (m *BaseModel) UpdateWithMapByCondition(t schema.Tabler, data map[string]interface{}, condition func(*gorm.DB) *gorm.DB) error

UpdateWithMapByCondition 使用map通过动态条件更新数据信息

type BaseSuite

type BaseSuite struct {
	suite.Suite
	SqlDB   *sql.DB
	SqlMock sqlmock.Sqlmock
	GormDB  *gorm.DB
}

BaseSuite 基础测试套

func (*BaseSuite) SetupSuite

func (s *BaseSuite) SetupSuite()

SetupSuite 初始化测试套

func (*BaseSuite) TearDownSuite

func (s *BaseSuite) TearDownSuite()

TearDownSuite 结束测试套

func (*BaseSuite) TestParseUpdateMap

func (s *BaseSuite) TestParseUpdateMap()

TestParseUpdateMap 测试解析更新map

func (*BaseSuite) TestStatement

func (s *BaseSuite) TestStatement()

TestStatement 测试表达式

type ByInfo

type ByInfo struct {
	CreateBy int64 `json:"create_by" gorm:"column:create_by;type:bigint(20);comment:创建者"` // 创建者
	UpdateBy int64 `json:"update_by" gorm:"column:update_by;type:bigint(20);comment:更新者"` // 更新者
}

ByInfo 操作者信息

func (*ByInfo) BeforeCreate

func (bi *ByInfo) BeforeCreate(tx *gorm.DB) error

BeforeCreate 创建前钩子函数

func (*ByInfo) BeforeUpdate

func (bi *ByInfo) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate 更新前钩子函数

type ContextKey

type ContextKey string

ContextKey 上下文key类型

func (ContextKey) String

func (c ContextKey) String() string

String 实现序列化字符串方法

type IdGetter

type IdGetter interface {
	schema.Tabler
	// GetId 获取id
	GetId() int64
}

IdGetter id获取器

type PaginationQuery

type PaginationQuery struct {
	// contains filtered or unexported fields
}

PaginationQuery 分页查询

func NewPaginationQuery

func NewPaginationQuery(page, pageSize int64, order string) *PaginationQuery

NewPaginationQuery 新建分页查询

func (*PaginationQuery) Add

func (pq *PaginationQuery) Add(query func(*gorm.DB) *gorm.DB)

Add 添加查询条件

func (*PaginationQuery) Paginate

func (pq *PaginationQuery) Paginate() func(*gorm.DB) *gorm.DB

Paginate 构建分页查询

func (*PaginationQuery) Queries

func (pq *PaginationQuery) Queries() func(*gorm.DB) *gorm.DB

Queries 获取查询条件

type TimeInfo

type TimeInfo struct {
	CreateTime int64 `json:"create_time" gorm:"column:create_time;type:bigint(20);autoCreateTime:milli;comment:创建时间"` // 创建时间
	UpdateTime int64 `json:"update_time" gorm:"column:update_time;type:bigint(20);autoUpdateTime:milli;comment:更新时间"` // 更新时间
}

TimeInfo 通用时间信息

Jump to

Keyboard shortcuts

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