bbs-backend/dal/db.go
2024-11-19 21:08:28 +08:00

20 lines
324 B
Go

// file name: db.go
package dal
import (
"bbs-backend/config"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"log"
)
var DB *gorm.DB
func InitDB() {
var err error
DB, err = gorm.Open(sqlite.Open(config.GetConfig().Database.File), &gorm.Config{})
if err != nil {
log.Fatalf("Failed to connect to database: %v", err)
}
}