Feat: support sqlite
This commit is contained in:
parent
e05ba1030c
commit
f46b52b6ba
4 changed files with 15 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,6 +4,7 @@
|
||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
*.db
|
||||||
|
|
||||||
# Test binary, build with `go test -c`
|
# Test binary, build with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
|
|
@ -8,12 +8,13 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||||
|
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DB 数据库链接单例
|
// DB 数据库链接单例
|
||||||
var DB *gorm.DB
|
var DB *gorm.DB
|
||||||
|
|
||||||
// Database 初始化 MySQL 链接
|
// Init 初始化 MySQL 链接
|
||||||
func Init() {
|
func Init() {
|
||||||
util.Log().Info("初始化数据库连接")
|
util.Log().Info("初始化数据库连接")
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ func Init() {
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
if conf.DatabaseConfig.Type == "UNSET" {
|
if conf.DatabaseConfig.Type == "UNSET" {
|
||||||
//TODO 使用内置SQLite数据库
|
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",
|
||||||
conf.DatabaseConfig.User,
|
conf.DatabaseConfig.User,
|
||||||
|
|
|
@ -25,7 +25,10 @@ func migration() {
|
||||||
util.Log().Info("开始进行数据库自动迁移...")
|
util.Log().Info("开始进行数据库自动迁移...")
|
||||||
|
|
||||||
// 自动迁移模式
|
// 自动迁移模式
|
||||||
DB.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{}, &Folder{}, &File{})
|
if conf.DatabaseConfig.Type == "mysql" {
|
||||||
|
DB = DB.Set("gorm:table_options", "ENGINE=InnoDB")
|
||||||
|
}
|
||||||
|
DB.AutoMigrate(&User{}, &Setting{}, &Group{}, &Policy{}, &Folder{}, &File{})
|
||||||
|
|
||||||
// 创建初始存储策略
|
// 创建初始存储策略
|
||||||
addDefaultPolicy()
|
addDefaultPolicy()
|
||||||
|
|
|
@ -37,6 +37,13 @@ type FileSystem struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewFileSystem 初始化一个文件系统
|
||||||
|
func NewFileSystem(user *model.User) *FileSystem {
|
||||||
|
return &FileSystem{
|
||||||
|
User: user,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Upload 上传文件
|
// Upload 上传文件
|
||||||
func (fs *FileSystem) Upload(file FileData) (err error) {
|
func (fs *FileSystem) Upload(file FileData) (err error) {
|
||||||
err = fs.BeforeUpload(fs, file)
|
err = fs.BeforeUpload(fs, file)
|
||||||
|
|
Loading…
Add table
Reference in a new issue