|
|
|
@ -4,6 +4,7 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/HFO4/cloudreve/pkg/conf"
|
|
|
|
|
"github.com/HFO4/cloudreve/pkg/util"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
@ -22,7 +23,13 @@ func Init() {
|
|
|
|
|
db *gorm.DB
|
|
|
|
|
err error
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if gin.Mode() == gin.TestMode {
|
|
|
|
|
// 测试模式下,使用内存数据库
|
|
|
|
|
db, err = gorm.Open("sqlite3", ":memory:")
|
|
|
|
|
} else {
|
|
|
|
|
if conf.DatabaseConfig.Type == "UNSET" {
|
|
|
|
|
// 未指定数据库时,使用Sqlite
|
|
|
|
|
db, err = gorm.Open("sqlite3", "cloudreve.db")
|
|
|
|
|
} else {
|
|
|
|
|
db, err = gorm.Open(conf.DatabaseConfig.Type, fmt.Sprintf("%s:%s@(%s)/%s?charset=utf8&parseTime=True&loc=Local",
|
|
|
|
@ -31,6 +38,7 @@ func Init() {
|
|
|
|
|
conf.DatabaseConfig.Host,
|
|
|
|
|
conf.DatabaseConfig.Name))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理表前缀
|
|
|
|
|
gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
|
|
|
|
|