From 421e596eb6537dac4a95d04f743848483361cdff Mon Sep 17 00:00:00 2001 From: Lewis Steele Date: Sun, 6 Oct 2024 12:22:33 +0100 Subject: [PATCH] Move db.go into db dir --- internal/{ => db}/db.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) rename internal/{ => db}/db.go (62%) diff --git a/internal/db.go b/internal/db/db.go similarity index 62% rename from internal/db.go rename to internal/db/db.go index 2968a83..8114221 100644 --- a/internal/db.go +++ b/internal/db/db.go @@ -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") @@ -23,8 +19,10 @@ 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), }) @@ -32,7 +30,5 @@ func init() { panic("could not connect to sqlite db") } - conn.AutoMigrate(&model.Database{}) - - localDB = conn + LocalDB.AutoMigrate(&model.Database{}) }