refactor:
- source 初始化数据 new 实现 - service mysql 与 pgsql 分开实现 - 代码备注优化
This commit is contained in:
34
server/source/example/file.go
Normal file
34
server/source/example/file.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package example
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var File = new(file)
|
||||
|
||||
type file struct{}
|
||||
|
||||
func (f *file) TableName() string {
|
||||
return "exa_file_upload_and_downloads"
|
||||
}
|
||||
|
||||
func (f *file) Initialize() error {
|
||||
entities := []example.ExaFileUploadAndDownload{
|
||||
{Name: "10.png", Url: "https://qmplusimg.henrongyi.top/gvalogo.png", Tag: "png", Key: "158787308910.png"},
|
||||
{Name: "logo.png", Url: "https://qmplusimg.henrongyi.top/1576554439myAvatar.png", Tag: "png", Key: "1587973709logo.png"},
|
||||
}
|
||||
if err := global.GVA_DB.Create(&entities).Error; err != nil {
|
||||
return errors.Wrap(err, f.TableName()+"表数据初始化失败!")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *file) CheckDataExist() bool {
|
||||
if errors.Is(global.GVA_DB.Where("name = ? AND key = ?", "logo.png", "1587973709logo.png").First(&example.ExaFileUploadAndDownload{}).Error, gorm.ErrRecordNotFound) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user