region.go 792 B

12345678910111213141516171819202122232425262728293031
  1. package dao
  2. import "server/global"
  3. type Region struct {
  4. global.GVA_MODEL
  5. Name string `json:"name" form:"name" gorm:"comment:名称;column:name"`
  6. Remarks string `json:"remarks" form:"remarks" gorm:"comment"`
  7. Tunnels []Tunnel `json:"tunnels" form:"tunnels" gorm:"foreignKey:RegionId"`
  8. }
  9. func (Region) TableName() string {
  10. return "region"
  11. }
  12. func QueryAllRegions() (regions []Region, err error) {
  13. err = global.GVA_DB.Preload("Tunnels").Find(&regions).Error
  14. return regions, err
  15. }
  16. func (r Region) CreateRegion() error {
  17. return global.GVA_DB.Create(&r).Error
  18. }
  19. func (r Region) UpdateRegion() error {
  20. return global.GVA_DB.Where("id = ?", r.ID).Updates(&r).Error
  21. }
  22. func DeleteRegion(id int) error {
  23. return global.GVA_DB.Unscoped().Where("id = ?", id).Delete(&Region{}).Error
  24. }