Skip to content

Commit

Permalink
stores: fix param order
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Feb 19, 2024
1 parent 083e360 commit 6a7f8b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 1 addition & 3 deletions stores/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ func NewMetricsSQLiteConnection(path string) gorm.Dialector {

// NewMySQLConnection creates a connection to a MySQL database.
func NewMySQLConnection(user, password, addr, dbName string) gorm.Dialector {
connString := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true", user, password, addr, dbName)
fmt.Println("DEBUG PJ: MySQL conn string", connString)
return mysql.Open(connString)
return mysql.Open(fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local&multiStatements=true", user, password, addr, dbName))
}

func DBConfigFromEnv() (uri, user, password, dbName string) {
Expand Down
6 changes: 3 additions & 3 deletions stores/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ func newTestSQLStore(t *testing.T, cfg testSQLStoreConfig) *testSQLStore {

var conn, connMetrics gorm.Dialector
if dbURI != "" {
if tmpDB, err := gorm.Open(NewMySQLConnection(dbURI, dbUser, dbPassword, "")); err != nil {
if tmpDB, err := gorm.Open(NewMySQLConnection(dbUser, dbPassword, dbURI, "")); err != nil {
t.Fatal(err)
} else if err := tmpDB.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s`", dbName)).Error; err != nil {
t.Fatal(err)
} else if err := tmpDB.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s`", dbMetricsName)).Error; err != nil {
t.Fatal(err)
}

conn = NewMySQLConnection(dbURI, dbUser, dbPassword, dbName)
connMetrics = NewMySQLConnection(dbURI, dbUser, dbPassword, dbMetricsName)
conn = NewMySQLConnection(dbUser, dbPassword, dbURI, dbName)
connMetrics = NewMySQLConnection(dbUser, dbPassword, dbURI, dbMetricsName)
} else if cfg.persistent {
conn = NewSQLiteConnection(filepath.Join(cfg.dir, "db.sqlite"))
connMetrics = NewSQLiteConnection(filepath.Join(cfg.dir, "metrics.sqlite"))
Expand Down

0 comments on commit 6a7f8b0

Please sign in to comment.