common

package
v0.0.0-...-01c5a3f Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomTime

type CustomTime time.Time

自定义时间类型,为了能够自定义时间类型的反序列化格式

func (CustomTime) MarshalJSON

func (t CustomTime) MarshalJSON() ([]byte, error)

自定义时间类型的反序列化格式,可参考Go/src/time/time.go的MarshalJSON

func (*CustomTime) Scan

func (t *CustomTime) Scan(value interface{}) error

实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb

func (CustomTime) String

func (t CustomTime) String() string

func (*CustomTime) UnmarshalJSON

func (t *CustomTime) UnmarshalJSON(data []byte) error

自定义时间类型的序列化格式,可参考Go/src/time/time.go的UnmarshalJSON

func (CustomTime) Value

func (t CustomTime) Value() (driver.Value, error)

实现 driver.Valuer 接口,Value 返回 json value

type ExtraModel

type ExtraModel struct {
	Name     string `gorm:"column:name;comment:名称" json:"name" form:"name"`                //  名称
	IsEnable *bool  `gorm:"column:is_enable;comment:是否启用" json:"isEnable" form:"isEnable"` //  是否启用
	Sort     *int64 `gorm:"column:sort;comment:排序" json:"sort" form:"sort"`                //  排序
}

额外的通用模型,包含:名称,是否启用,排序

type Model

type Model struct {
	Id         int64          `gorm:"column:id;comment:Id;primarykey" json:"id" form:"id"`                           //  Id
	CreateTime CustomTime     `gorm:"column:create_time;comment:创建时间;<-:create" json:"createTime" form:"createTime"` //  创建时间,格式:yyyy-MM-dd HH:mm:ss
	UpdateTime CustomTime     `gorm:"column:update_time;comment:修改时间" json:"updateTime" form:"updateTime"`           //  修改时间,格式:yyyy-MM-dd HH:mm:ss
	DeleteTime gorm.DeletedAt `gorm:"column:delete_time;comment:删除时间;index" json:"-" form:"deleteTime"`              //  删除时间,格式:yyyy-MM-dd HH:mm:ss
}

通用模型,参考gorm.Model

func (*Model) BeforeCreate

func (m *Model) BeforeCreate(tx *gorm.DB) (err error)

模型创建前的钩子,给创建时间和修改时间赋值

func (*Model) BeforeUpdate

func (m *Model) BeforeUpdate(tx *gorm.DB) (err error)

模型修改前的钩子,给修改时间赋值

Jump to

Keyboard shortcuts

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