gormodel

package
v0.0.0-...-63b2ac5 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonTime

type JsonTime struct {
	time.Time
}

http://www.axiaoxin.com/article/241/

func (JsonTime) MarshalJSON

func (jtime JsonTime) MarshalJSON() ([]byte, error)

所以我们只需定义一个内嵌time.Time的结构体,并重写MarshalJSON方法,然后在定义model的时候把time.Time类型替换为我们自己的类型即可。但是在gorm中只重写MarshalJSON是不够的,只写这个方法会在写数据库的时候会提示delete_at字段不存在,需要加上database/sql的Value和Scan方法 https://github.com/jinzhu/gorm/issues/1611#issuecomment-329654638

func (*JsonTime) Scan

func (t *JsonTime) Scan(v interface{}) error

Scan valueof time.Time

func (JsonTime) String

func (jtime JsonTime) String() string

func (JsonTime) Value

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

Value insert timestamp into mysql need this function.

type ModelId

type ModelId struct {
	ID uint `gorm:"primary_key"`
}

主键id

type ModelSofeDel

type ModelSofeDel struct {
	DeletedAt *JsonTime
}

软删除

type ModelTime

type ModelTime struct {
	CreatedAt JsonTime
	UpdatedAt JsonTime
}

TODO 需要研究下 gorm中的回调机制 https://www.cnblogs.com/sgyBlog/p/10154424.html 创建和修改时间

type ModelUuid

type ModelUuid struct {
	Uuid string `gorm:"type:varchar(32);unique;"`
}

func (*ModelUuid) Get

func (this *ModelUuid) Get() string

Jump to

Keyboard shortcuts

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