fix: need to update config management in db pkg
This commit is contained in:
parent
bbfea6fc9e
commit
051cf59195
18
db/db.go
18
db/db.go
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue