schreifuchs 0f710b8d9f
All checks were successful
build / windows (push) Successful in 2m32s
build / linux (push) Successful in 1m52s
added workflow
Reviewed-on: #1
2025-03-03 13:30:39 +01:00

36 lines
479 B
Go

package model
import (
"log"
"os"
"path"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type Thing struct {
ID int
Name string
Subthings []SubThing
}
type SubThing struct {
ID int
ThingID int
Name string
}
func InitDB() *gorm.DB {
home, err := os.UserHomeDir()
if err != nil {
panic(err)
}
db, err := gorm.Open(sqlite.Open(path.Join(home, "things.db")))
if err != nil {
log.Panic(err)
}
db.AutoMigrate(&Thing{}, &SubThing{})
return db
}