123456789101112131415161718192021222324252627282930313233 |
- package db
- import (
- "github.com/astaxie/beego/orm"
- _ "github.com/mattn/go-sqlite3"
- "nginx-ui/server/config"
- "nginx-ui/server/models"
- "nginx-ui/server/utils"
- "os"
- "time"
- )
- func Init() {
- dir := config.Config.DBDir
- if !utils.IsExist(dir) {
- os.MkdirAll(dir, 0777)
- }
- orm.RegisterDriver("sqlite3", orm.DRSqlite)
- orm.RegisterDataBase("default", "sqlite3", dir+"/sqlite.db")
- orm.SetMaxIdleConns("default", 50)
- orm.SetMaxOpenConns("default", 200)
- //设置数据库时区
- orm.DefaultTimeLoc = time.Local
- orm.RegisterModel(new(models.Nginx))
- orm.RegisterModel(new(models.ServerHost))
- orm.RegisterModel(new(models.NginxCerts))
- orm.RegisterModel(new(models.User))
- orm.RunSyncdb("default", false, true)
- }
|