model.go 429 B

12345678910111213141516171819202122232425262728
  1. package models
  2. import (
  3. "git.qianqiusoft.com/qianqiusoft/light-apiengine/config"
  4. "github.com/xormplus/xorm"
  5. "sync"
  6. )
  7. var beans []interface{}
  8. var beansLock sync.Mutex
  9. func RegisterModel(models ...interface{}) {
  10. beansLock.Lock()
  11. defer beansLock.Unlock()
  12. for _, model := range models {
  13. beans = append(beans, model)
  14. }
  15. }
  16. func SyncDb(db *xorm.Engine) {
  17. if !config.AppConfig.SyncDb {
  18. return
  19. }
  20. db.Sync2(beans...)
  21. }