Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithunikzz committed Oct 30, 2023
1 parent dc0db09 commit db2f207
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions cmd/cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,26 @@ func OpenClickHouseConn() (*sql.DB, *Config, error) {
if err != nil {
return nil, nil, err
}
//var conn clickhouse.Options
var conns clickhouse.Options

conn := clickhouse.OpenDB(&clickhouse.Options{
Addr: []string{
fmt.Sprintf("%s:%d", cfg.DBAddress, cfg.DbPort)},
Debug: true,
Auth: clickhouse.Auth{
Username: cfg.ClickHouseUsername,
Password: cfg.ClickHousePassword,
},
})
// if cfg.ClickHouseUsername != "" && cfg.ClickHousePassword != "" {
// fmt.Println("Using provided username and password")
// conn = clickhouse.Options{
// Addr: []string{fmt.Sprintf("%s:%d", cfg.DBAddress, cfg.DbPort)},
// Debug: true,
// Auth: clickhouse.Auth{
// Username: cfg.ClickHouseUsername,
// Password: cfg.ClickHousePassword,
// },
// }
// } else {
// fmt.Println("Using connection without username and password")
// conn = clickhouse.Options{
// Addr: []string{fmt.Sprintf("%s:%d", conf.DBAddress, conf.DbPort)},
// }
// }
if cfg.ClickHouseUsername != "" && cfg.ClickHousePassword != "" {
fmt.Println("Using provided username and password")
conns = clickhouse.Options{
Addr: []string{fmt.Sprintf("%s:%d", cfg.DBAddress, cfg.DbPort)},
Debug: true,
Auth: clickhouse.Auth{
Username: cfg.ClickHouseUsername,
Password: cfg.ClickHousePassword,
},
}
} else {
fmt.Println("Using connection without username and password")
conns = clickhouse.Options{
Addr: []string{fmt.Sprintf("%s:%d", cfg.DBAddress, cfg.DbPort)},
}
}

// conn = clickhouse.OpenDB(&conn)
conn := clickhouse.OpenDB(&conns)
if err := conn.Ping(); err != nil {
if exception, ok := err.(*clickhouse.Exception); ok {
return nil, nil, fmt.Errorf("[%d] %s %s", exception.Code, exception.Message, exception.StackTrace)
Expand Down

0 comments on commit db2f207

Please sign in to comment.