mirror of
https://github.com/nitezs/sub2clash.git
synced 2024-12-25 01:14:42 -05:00
27 lines
414 B
Go
27 lines
414 B
Go
package database
|
|
|
|
import (
|
|
"github.com/glebarez/sqlite"
|
|
"gorm.io/gorm"
|
|
"sub2clash/model"
|
|
)
|
|
|
|
var DB *gorm.DB
|
|
|
|
func ConnectDB() error {
|
|
// 用上面的数据库连接初始化 gorm
|
|
db, err := gorm.Open(sqlite.Open("sub2clash.db"), &gorm.Config{})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
DB = db
|
|
err = db.AutoMigrate(&model.ShortLink{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|