blt/models/init.go
2024-05-29 11:25:45 -04:00

27 lines
471 B
Go

package models
import (
"log"
"gorm.io/gorm"
"gorm.io/driver/sqlite"
)
var (
DB *gorm.DB
)
// Initializes the Gorm database object
func Open() {
// Initialize database object
var err error
DB, err = gorm.Open(sqlite.Open("data/blt.db"), &gorm.Config{})
if err != nil {
panic("Failed to connect database")
}
// Migrate the schema
DB.AutoMigrate(&Test{}, &Hardware{}, &Benchmark{}, &Result{})
log.Println("Database migrations complete.")
}