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