Skip to content

Commit

Permalink
Move db.go into db dir
Browse files Browse the repository at this point in the history
  • Loading branch information
lewissteele committed Oct 6, 2024
1 parent 33afa0b commit 421e596
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions internal/db.go → internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import (
"gorm.io/gorm/logger"
)

var localDB *gorm.DB

func SaveConnection(host string, username string, password string) {
localDB.Create(&model.Database{Host: "localhost", Username: "root", Password: ""})
}
var LocalDB *gorm.DB

func init() {
configHome := os.Getenv("XDG_CONFIG_HOME")
Expand All @@ -23,16 +19,16 @@ func init() {
configHome = filepath.Join(os.Getenv("HOME"), ".config")
}

var err error
path := filepath.Join(configHome, "dbat/dbat.db")
conn, err := gorm.Open(sqlite.Open(path), &gorm.Config{

LocalDB, err = gorm.Open(sqlite.Open(path), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
})

if err != nil {
panic("could not connect to sqlite db")
}

conn.AutoMigrate(&model.Database{})

localDB = conn
LocalDB.AutoMigrate(&model.Database{})
}

0 comments on commit 421e596

Please sign in to comment.