Added Gorm to project

This commit is contained in:
2023-11-27 22:36:58 -05:00
parent 0ee3d06f89
commit 49925c6d8f
7 changed files with 53 additions and 0 deletions

20
models/init.go Normal file
View 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.")
}

11
models/project.go Normal file
View File

@ -0,0 +1,11 @@
package models
import (
"gorm.io/gorm"
)
type Project struct {
gorm.Model
Name string
Description string
}