1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-25 08:50:54 -05:00
sub2clash/utils/database/database.go

27 lines
414 B
Go
Raw Normal View History

2023-09-17 03:52:37 -04:00
package database
import (
"github.com/glebarez/sqlite"
2023-09-17 03:52:37 -04:00
"gorm.io/gorm"
"sub2clash/model"
)
var DB *gorm.DB
func ConnectDB() error {
// 用上面的数据库连接初始化 gorm
2023-09-17 03:52:37 -04:00
db, err := gorm.Open(sqlite.Open("sub2clash.db"), &gorm.Config{})
if err != nil {
panic(err)
}
2023-09-17 03:52:37 -04:00
if err != nil {
return err
}
DB = db
err = db.AutoMigrate(&model.ShortLink{})
if err != nil {
return err
}
return nil
}