package main import ( "gorm.io/driver/sqlite" "gorm.io/gorm" ) type Repository struct { db *gorm.DB game *Game } func NewRepository(gameName string) (*Repository, error) { db, err := gorm.Open(sqlite.Open("mythic.db"), &gorm.Config{}) if err != nil { return nil, err } game := &Game{ Name: gameName, } return &Repository{ db: db, game: game, }, nil } func (r *Repository) initGame(game *Game) error { // TODO: Figure out why this check doesn't work r.db.AutoMigrate(game) r.db.FirstOrCreate(game) err := r.initFate(game) if err != nil { return err } return nil } func (r *Repository) initFate(game *Game) error { // TODO: populate fate table r.db.AutoMigrate(&Fate{}) r.db.Create(&Fate{ Game: game, Odds: 1, Chaos: 1, Low: 10, Middle: 50, High: 91, }) return nil }