fix: need to update config management in db pkg

This commit is contained in:
Derrick Hammer 2024-02-22 03:30:40 -05:00
parent bbfea6fc9e
commit 051cf59195
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 8 deletions

View File

@ -3,8 +3,10 @@ package db
import ( import (
"context" "context"
"fmt" "fmt"
"git.lumeweb.com/LumeWeb/portal/config"
"git.lumeweb.com/LumeWeb/portal/db/models" "git.lumeweb.com/LumeWeb/portal/db/models"
"github.com/spf13/viper"
"go.uber.org/fx" "go.uber.org/fx"
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/gorm" "gorm.io/gorm"
@ -12,7 +14,7 @@ import (
type DatabaseParams struct { type DatabaseParams struct {
fx.In fx.In
Config *viper.Viper Config *config.Manager
} }
var Module = fx.Module("db", var Module = fx.Module("db",
@ -22,12 +24,12 @@ var Module = fx.Module("db",
) )
func NewDatabase(lc fx.Lifecycle, params DatabaseParams) *gorm.DB { func NewDatabase(lc fx.Lifecycle, params DatabaseParams) *gorm.DB {
username := params.Config.GetString("core.db.username") username := params.Config.Config().Core.DB.Username
password := params.Config.GetString("core.db.password") password := params.Config.Config().Core.DB.Password
host := params.Config.GetString("core.db.host") host := params.Config.Config().Core.DB.Host
port := params.Config.GetString("core.db.port") port := params.Config.Config().Core.DB.Port
dbname := params.Config.GetString("core.db.name") dbname := params.Config.Config().Core.DB.Name
charset := params.Config.GetString("core.db.charset") charset := params.Config.Config().Core.DB.Charset
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=%s&parseTime=True&loc=Local", username, password, host, port, dbname, charset) dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=%s&parseTime=True&loc=Local", username, password, host, port, dbname, charset)