正在显示
2 个修改的文件
包含
38 行增加
和
1 行删除
1 | package models | 1 | package models |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "context" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/go-pg/pg/v10" | ||
8 | +) | ||
4 | 9 | ||
5 | // 公司信息 | 10 | // 公司信息 |
6 | type Company struct { | 11 | type Company struct { |
@@ -30,3 +35,18 @@ type Company struct { | @@ -30,3 +35,18 @@ type Company struct { | ||
30 | // 删除时间 | 35 | // 删除时间 |
31 | DeleteAt time.Time | 36 | DeleteAt time.Time |
32 | } | 37 | } |
38 | + | ||
39 | +var _ pg.BeforeUpdateHook = (*Company)(nil) | ||
40 | + | ||
41 | +func (c *Company) BeforeUpdate(ctx context.Context) (context.Context, error) { | ||
42 | + c.UpdateAt = time.Now() | ||
43 | + return ctx, nil | ||
44 | +} | ||
45 | + | ||
46 | +var _ pg.BeforeInsertHook = (*Company)(nil) | ||
47 | + | ||
48 | +func (c *Company) BeforeInsert(ctx context.Context) (context.Context, error) { | ||
49 | + c.CreateAt = time.Now() | ||
50 | + c.UpdateAt = time.Now() | ||
51 | + return ctx, nil | ||
52 | +} |
1 | package models | 1 | package models |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "context" | ||
4 | "time" | 5 | "time" |
5 | 6 | ||
7 | + "github.com/go-pg/pg/v10" | ||
6 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" |
7 | ) | 9 | ) |
8 | 10 | ||
@@ -31,3 +33,18 @@ type Users struct { | @@ -31,3 +33,18 @@ type Users struct { | ||
31 | UpdateAt time.Time | 33 | UpdateAt time.Time |
32 | DeleteAt time.Time | 34 | DeleteAt time.Time |
33 | } | 35 | } |
36 | + | ||
37 | +var _ pg.BeforeUpdateHook = (*Users)(nil) | ||
38 | + | ||
39 | +func (user *Users) BeforeUpdate(ctx context.Context) (context.Context, error) { | ||
40 | + user.UpdateAt = time.Now() | ||
41 | + return ctx, nil | ||
42 | +} | ||
43 | + | ||
44 | +var _ pg.BeforeInsertHook = (*Users)(nil) | ||
45 | + | ||
46 | +func (user *Users) BeforeInsert(ctx context.Context) (context.Context, error) { | ||
47 | + user.CreateAt = time.Now() | ||
48 | + user.UpdateAt = time.Now() | ||
49 | + return ctx, nil | ||
50 | +} |
-
请 注册 或 登录 后发表评论