package dao import ( "errors" "yintai-api/app/common/model" "gorm.io/gorm" ) type Config struct { db *gorm.DB } func NewConfig(db ...*gorm.DB) *Config { return &Config{db: getDB(db...)} } func (r *Config) TableName() string { return "yt_config" } func (r *Config) Create(m *model.Config) error { return r.db.Table(r.TableName()).Create(m).Error } func (r *Config) Update(m *model.Config) error { return r.db.Table(r.TableName()).Save(m).Error } func (r *Config) Delete(id int64) error { return r.db.Table(r.TableName()).Where("id = ?", id).Delete(&Config{}).Error } func (r *Config) Get(id int64) (*model.Config, error) { var res model.Config if err := r.db.Table(r.TableName()).Where("id = ?", id).First(&res).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return nil, nil } return nil, err } return &res, nil } func (r *Config) Exists(id int64) (bool, error) { var count int64 if err := r.db.Table(r.TableName()).Where("id = ?", id).Count(&count).Error; err != nil { return false, err } return count > 0, nil } func (r *Config) List(...any) ([]*model.Config, int64, error) { panic("implement me") }