package dao import "server/global" type Region struct { global.GVA_MODEL Name string `json:"name" form:"name" gorm:"comment:名称;column:name"` Remarks string `json:"remarks" form:"remarks" gorm:"comment"` Tunnels []Tunnel `json:"tunnels" form:"tunnels" gorm:"foreignKey:RegionId"` } func (Region) TableName() string { return "region" } func QueryAllRegions() (regions []Region, err error) { err = global.GVA_DB.Preload("Tunnels").Find(®ions).Error return regions, err } func (r Region) CreateRegion() error { return global.GVA_DB.Create(&r).Error } func (r Region) UpdateRegion() error { return global.GVA_DB.Where("id = ?", r.ID).Updates(&r).Error } func DeleteRegion(id int) error { return global.GVA_DB.Unscoped().Where("id = ?", id).Delete(&Region{}).Error }