You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.0 KiB

  1. package example
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/example"
  5. "github.com/pkg/errors"
  6. "gorm.io/gorm"
  7. )
  8. var FileMysql = new(fileMysql)
  9. type fileMysql struct{}
  10. func (f *fileMysql) TableName() string {
  11. return "exa_file_upload_and_downloads"
  12. }
  13. func (f *fileMysql) Initialize() error {
  14. entities := []example.ExaFileUploadAndDownload{
  15. {Name: "10.png", Url: "https://qmplusimg.henrongyi.top/gvalogo.png", Tag: "png", Key: "158787308910.png"},
  16. {Name: "logo.png", Url: "https://qmplusimg.henrongyi.top/1576554439myAvatar.png", Tag: "png", Key: "1587973709logo.png"},
  17. }
  18. if err := global.GVA_DB.Create(&entities).Error; err != nil {
  19. return errors.Wrap(err, f.TableName()+"表数据初始化失败!")
  20. }
  21. return nil
  22. }
  23. func (f *fileMysql) CheckDataExist() bool {
  24. if errors.Is(global.GVA_DB.Where("`name` = ? AND `key` = ?", "logo.png", "1587973709logo.png").First(&example.ExaFileUploadAndDownload{}).Error, gorm.ErrRecordNotFound) {
  25. return false
  26. }
  27. return true
  28. }