package entities import ( "context" "time" "github.com/uptrace/bun" ) type User struct { ID int32 `bun:",pk,autoincrement"` Email string `bun:",notnull,unique"` PasswordHash string `bun:",notnull,type:varchar(64)"` PasswordLength int8 `bun:",notnull"` RealName string `bun:",notnull"` GroupID int32 `bun:",notnull"` Group *Group `bun:"rel:belongs-to,join:group_id=id"` IsRequiredToSetPassword bool `bun:",notnull,default:true"` IsActive bool `bun:",notnull,default:true"` LastLogin time.Time CreatedAt time.Time `bun:",notnull,default:current_timestamp"` UpdatedAt time.Time DeletedAt time.Time `bun:",soft_delete,nullzero"` } var _ bun.BeforeAppendModelHook = (*User)(nil) func (u *User) BeforeAppendModel(ctx context.Context, query bun.Query) error { switch query.(type) { case *bun.UpdateQuery: u.UpdatedAt = time.Now() } return nil }