device_genre.go 888 B

1234567891011121314151617181920212223242526272829303132333435
  1. package dao
  2. import "server/global"
  3. type DeviceGenre struct {
  4. global.GVA_MODEL
  5. Name string `json:"name" form:"name" gorm:"comment:类型名称"`
  6. Type string `json:"type" form:"type" gorm:"comment:硬件类型"`
  7. }
  8. func (DeviceGenre) TableName() string {
  9. return "device_genre"
  10. }
  11. func QueryAllDeviceGenres() (genres []DeviceGenre, err error) {
  12. err = global.GVA_DB.Model(DeviceGenre{}).Find(&genres).Error
  13. return
  14. }
  15. func QueryDeviceGenreByID(id int) (genre DeviceGenre, err error) {
  16. err = global.GVA_DB.Where("id = ?", id).First(&genre).Error
  17. return
  18. }
  19. func (d DeviceGenre) CreateDeviceGenre() error {
  20. return global.GVA_DB.Create(&d).Error
  21. }
  22. func (d DeviceGenre) UpdateDeviceGenre() error {
  23. return global.GVA_DB.Where("id = ?", d.ID).Updates(&d).Error
  24. }
  25. func DeleteDeviceGenre(id int) error {
  26. return global.GVA_DB.Unscoped().Where("id = ?", id).Delete(&DeviceGenre{}).Error
  27. }