20 lines
324 B
Go
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)
|
|
}
|
|
}
|