Skip to content

Commit

Permalink
better: skip connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Feb 12, 2024
1 parent ec8f814 commit 9ffcb66
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions flow/connectors/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"context"
"database/sql"
"fmt"
"net/url"

_ "github.com/ClickHouse/clickhouse-go/v2"
"github.com/ClickHouse/clickhouse-go/v2"
_ "github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"go.temporal.io/sdk/log"

Expand Down Expand Up @@ -79,16 +78,17 @@ func NewClickhouseConnector(
}

func connect(ctx context.Context, config *protos.ClickhouseConfig) (*sql.DB, error) {
dsn := fmt.Sprintf("clickhouse://%s:%d/%s?username=%s&password=%s",
config.Host, config.Port,
url.PathEscape(config.Database), url.QueryEscape(config.User), url.QueryEscape(config.Password))

conn, err := sql.Open("clickhouse", dsn)
if err != nil {
return nil, fmt.Errorf("failed to open connection to Clickhouse peer: %w", err)
}
conn := clickhouse.OpenDB(&clickhouse.Options{
Addr: []string{fmt.Sprintf("%s:%d", config.Host, config.Port)},
Auth: clickhouse.Auth{
Database: config.Database,
Username: config.User,
Password: config.Password,
},
})

if err := conn.PingContext(ctx); err != nil {
conn.Close()
return nil, fmt.Errorf("failed to ping to Clickhouse peer: %w", err)
}

Expand Down

0 comments on commit 9ffcb66

Please sign in to comment.