1
0
mirror of https://github.com/IceWhaleTech/CasaOS.git synced 2025-07-15 23:54:17 +02:00
* switch branches

* update user interface

* switch branch

* switch branch

* change branch

* submit 0.3.3
This commit is contained in:
link
2022-06-29 11:09:58 +08:00
committed by GitHub
parent b0dc30277b
commit f99f49dd7e
127 changed files with 5751 additions and 7533 deletions

View File

@ -1,11 +1,22 @@
/*
* @Author: LinkLeong link@icewhale.com
* @Date: 2022-05-13 18:15:46
* @LastEditors: LinkLeong
* @LastEditTime: 2022-06-22 18:50:44
* @FilePath: /CasaOS/pkg/sqlite/db.go
* @Description:
* @Website: https://www.casaos.io
* Copyright (c) 2022 by icewhale, All Rights Reserved.
*/
package sqlite
import (
"fmt"
"time"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
model2 "github.com/IceWhaleTech/CasaOS/service/model"
"go.uber.org/zap"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
@ -16,7 +27,7 @@ func GetDb(dbPath string) *gorm.DB {
if gdb != nil {
return gdb
}
// 参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情
// Refer https://github.com/go-sql-driver/mysql#dsn-data-source-name
//dsn := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8mb4&parseTime=True&loc=Local", m.User, m.PWD, m.IP, m.Port, m.DBName)
//db, err := gorm.Open(mysql2.Open(dsn), &gorm.Config{})
file.IsNotExistMkDir(dbPath)
@ -26,14 +37,15 @@ func GetDb(dbPath string) *gorm.DB {
c.SetMaxOpenConns(100)
c.SetConnMaxIdleTime(time.Second * 1000)
if err != nil {
fmt.Println("连接数据失败!")
panic("数据库连接失败")
loger.Error("sqlite connect error", zap.Any("db connect error", err))
panic("sqlite connect error")
return nil
}
gdb = db
err = db.AutoMigrate(&model2.TaskDBModel{}, &model2.AppNotify{}, &model2.AppListDBModel{}, &model2.SerialDisk{}, model2.PersonDownloadDBModel{}, model2.FriendModel{}, model2.PersonDownRecordDBModel{}, model2.ApplicationModel{})
err = db.AutoMigrate(&model2.AppNotify{}, &model2.AppListDBModel{}, &model2.SerialDisk{}, model2.PersonDownloadDBModel{}, model2.FriendModel{}, model2.PersonDownRecordDBModel{}, model2.UserDBModel{})
db.Exec("DROP TABLE IF EXISTS o_application")
if err != nil {
fmt.Println("检查和创建数据库出错", err)
loger.Error("check or create db error", zap.Any("error", err))
}
return db
}