package database import ( "context" "time" "github.com/uptrace/bun" ) type Server struct { ID int64 `bun:",pk,autoincrement"` Hostname string `bun:",notnull" json:"hostname"` IP string `bun:",notnull"` IsOnline bool `bun:",notnull,default:true" json:"isOnline"` LastOnline time.Time `json:"lastOnline"` CreatedAt time.Time `bun:",notnull,default:current_timestamp" json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` } 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 }