mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 22:58:44 +05:00
Added DSNopts for stor_db
This commit is contained in:
committed by
Dan Christian Bogos
parent
b3879194c1
commit
5912e6aacf
@@ -32,14 +32,13 @@ type MySQLStorage struct {
|
||||
}
|
||||
|
||||
func NewMySQLStorage(host, port, name, user, password string,
|
||||
maxConn, maxIdleConn int, connMaxLifetime time.Duration, location string) (*SQLStorage, error) {
|
||||
maxConn, maxIdleConn int, connMaxLifetime time.Duration, location string, dsnParams map[string]string) (*SQLStorage, error) {
|
||||
connectString := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&loc=%s&parseTime=true&sql_mode='ALLOW_INVALID_DATES'",
|
||||
user, password, host, port, name, location)
|
||||
db, err := gorm.Open(mysql.Open(connectString), &gorm.Config{AllowGlobalUpdate: true})
|
||||
db, err := gorm.Open(mysql.Open(connectString+AppendToMysqlDSNOpts(dsnParams)), &gorm.Config{AllowGlobalUpdate: true})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mySQLStorage := new(MySQLStorage)
|
||||
if mySQLStorage.DB, err = db.DB(); err != nil {
|
||||
return nil, err
|
||||
@@ -60,6 +59,17 @@ func NewMySQLStorage(host, port, name, user, password string,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func AppendToMysqlDSNOpts(opts map[string]string) string {
|
||||
if opts != nil {
|
||||
var dsn string
|
||||
for key, val := range opts {
|
||||
dsn = dsn + "&" + key + "=" + val
|
||||
}
|
||||
return dsn
|
||||
}
|
||||
return utils.EmptyString
|
||||
}
|
||||
|
||||
// SetVersions will set a slice of versions, updating existing
|
||||
func (msqlS *MySQLStorage) SetVersions(vrs Versions, overwrite bool) (err error) {
|
||||
tx := msqlS.db.Begin()
|
||||
|
||||
@@ -69,7 +69,7 @@ func NewStorDBConn(dbType, host, port, name, user, pass, marshaler string,
|
||||
opts.SQLMaxOpenConns, opts.SQLMaxIdleConns, opts.SQLConnMaxLifetime)
|
||||
case utils.MySQL:
|
||||
db, err = NewMySQLStorage(host, port, name, user, pass, opts.SQLMaxOpenConns, opts.SQLMaxIdleConns,
|
||||
opts.SQLConnMaxLifetime, opts.MySQLLocation)
|
||||
opts.SQLConnMaxLifetime, opts.MySQLLocation, opts.SQLDSNParams)
|
||||
case utils.Internal:
|
||||
db = NewInternalDB(stringIndexedFields, prefixIndexedFields, itmsCfg)
|
||||
default:
|
||||
|
||||
@@ -74,7 +74,7 @@ func TestStorDBit(t *testing.T) {
|
||||
if storDB, err = NewMySQLStorage(storCfg.StorDbCfg().Host,
|
||||
storCfg.StorDbCfg().Port, storCfg.StorDbCfg().Name,
|
||||
storCfg.StorDbCfg().User, storCfg.StorDbCfg().Password,
|
||||
100, 10, 0, "UTC"); err != nil {
|
||||
100, 10, 0, "UTC", storCfg.StorDbCfg().Opts.SQLDSNParams); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
storDB.(*SQLStorage).db.Config.Logger = logger.Default.LogMode(logger.Silent)
|
||||
|
||||
Reference in New Issue
Block a user