Added Gorm to project
This commit is contained in:
20
models/init.go
Normal file
20
models/init.go
Normal file
@ -0,0 +1,20 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/driver/sqlite"
|
||||
)
|
||||
|
||||
func InitDatabase() {
|
||||
// Initialize database object
|
||||
db, err := gorm.Open(sqlite.Open("data/blt.db"), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("Failed to connect database")
|
||||
}
|
||||
|
||||
// Migrate the schema
|
||||
db.AutoMigrate(&Project{})
|
||||
log.Println("Database migrations complete.")
|
||||
}
|
Reference in New Issue
Block a user