package model import ( "context" "gorm.io/gorm" ) type ( jobListModel interface { Insert(ctx context.Context, data *JobList) error Update(ctx context.Context, jobId int32, updates map[string]any) error Delete(ctx context.Context, jobId int32) error FindOne(ctx context.Context, jobId int32) (*JobList, error) FindTitle(ctx context.Context, title string) (*JobList, error) } JobList struct { updates map[string]any JobId int32 `gorm:"column:jobId"` Title string `gorm:"column:title"` } defaultJobListModel struct { db *gorm.DB } ) func (s *JobList) TableName() string { return "job_list" } func NewJobList() *JobList { return &JobList{ updates: make(map[string]any), } } func (s *JobList) SetJobId(jobId int32) *JobList { s.JobId = jobId s.set("jobId", jobId) return s } func (s *JobList) SetTitle(title string) *JobList { s.Title = title s.set("title", title) return s } func (s *JobList) set(key string, val any) { s.updates[key] = val } func (s *JobList) UpdateColumn() map[string]any { return s.updates } func newJobListDAO(db *gorm.DB) *defaultJobListModel { return &defaultJobListModel{ db: db, } } func (s *defaultJobListModel) Insert(ctx context.Context, data *JobList) error { return s.db.Create(data).Error } func (s *defaultJobListModel) Update(ctx context.Context, jobId int32, updates map[string]any) error { return s.db.Model(JobList{}).Where("jobId=?", jobId).Updates(updates).Error } func (s *defaultJobListModel) Delete(ctx context.Context, jobId int32) error { return s.db.Where("jobId=?", jobId).Delete(&JobList{}).Error } func (s *defaultJobListModel) FindOne(ctx context.Context, jobId int32) (*JobList, error) { row := JobList{} err := s.db.Where("jobId=?", jobId).Find(&row).Error return findResultWithError(&row, err) } func (s *defaultJobListModel) FindTitle(ctx context.Context, title string) (*JobList, error) { row := JobList{} err := s.db.Where("title=?", title).Find(&row).Error return findResultWithError(&row, err) }