Added GORM to handle database

This commit is contained in:
2022-11-25 15:13:32 -05:00
parent 7c55247af0
commit 64fc6fd8fc
8 changed files with 74 additions and 2 deletions

12
models/component.go Normal file
View File

@ -0,0 +1,12 @@
package models
import (
"gorm.io/gorm"
)
type Component struct {
gorm.Model
Name string
Manufacturer string
Type string
}

17
models/init.go Normal file
View File

@ -0,0 +1,17 @@
package models
import (
"gorm.io/gorm"
"gorm.io/driver/sqlite"
)
var (
DB *gorm.DB
)
func InitDB() {
DB, _ = gorm.Open(sqlite.Open("data/colossus.db"), &gorm.Config{})
// Migrate the schema
DB.AutoMigrate(&Component{})
}