package entities import ( "context" "time" "github.com/uptrace/bun" ) type Server struct { ID int64 `bun:",pk,autoincrement"` Hostname string `bun:",notnull"` IP string `bun:",notnull"` IsOnline bool `bun:",notnull,default:true"` LastOnline time.Time CreatedAt time.Time `bun:",notnull,default:current_timestamp"` UpdatedAt time.Time } var _ bun.BeforeAppendModelHook = (*Server)(nil) func (s *Server) BeforeAppendModel(ctx context.Context, query bun.Query) error { switch query.(type) { case *bun.InsertQuery: s.LastOnline = time.Now() case *bun.UpdateQuery: s.UpdatedAt = time.Now() } return nil }