generated from schreifuchs/wails-template
Initial commit
This commit is contained in:
35
model/model.go
Normal file
35
model/model.go
Normal file
@ -0,0 +1,35 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user