Added GORM to handle database
This commit is contained in:
12
models/component.go
Normal file
12
models/component.go
Normal 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
17
models/init.go
Normal 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{})
|
||||
}
|
Reference in New Issue
Block a user