diff --git a/dburl_test.go b/dburl_test.go index 0eb7d32..0f1b3d4 100644 --- a/dburl_test.go +++ b/dburl_test.go @@ -949,6 +949,24 @@ func TestParse(t *testing.T) { `grpcs://user:pass@localhost:8888/?opt1=a&opt2=b`, ``, }, + { + `clickhouse://user:pass@localhost/?opt1=a&opt2=b`, + `clickhouse`, + `clickhouse://user:pass@localhost:9000/?opt1=a&opt2=b`, + ``, + }, + { + `clickhouse+http://user:pass@localhost/?opt1=a&opt2=b`, + `clickhouse`, + `http://user:pass@localhost/?opt1=a&opt2=b`, + ``, + }, + { + `clickhouse+https://user:pass@host/?opt1=a&opt2=b`, + `clickhouse`, + `https://user:pass@host/?opt1=a&opt2=b`, + ``, + }, } m := make(map[string]bool) for i, tt := range tests { diff --git a/dsn.go b/dsn.go index c3e26e3..691fdaa 100644 --- a/dsn.go +++ b/dsn.go @@ -157,6 +157,26 @@ func GenCassandra(u *URL) (string, string, error) { return host + ":" + port + genQueryOptions(q), "", nil } +// GenClickhouse generates a clickhouse DSN from the passed URL. +func GenClickhouse(u *URL) (string, string, error) { + switch strings.ToLower(u.Transport) { + case "", "tcp": + return clickhouseTCP(u) + case "http": + return clickhouseHTTP(u) + case "https": + return clickhouseHTTPS(u) + } + return "", "", ErrInvalidTransportProtocol +} + +// clickhouse generators. +var ( + clickhouseTCP = GenFromURL("clickhouse://localhost:9000/") + clickhouseHTTP = GenFromURL("http://localhost/") + clickhouseHTTPS = GenFromURL("https://localhost/") +) + // GenCosmos generates a cosmos DSN from the passed URL. func GenCosmos(u *URL) (string, string, error) { host, port, dbname := u.Hostname(), u.Port(), strings.TrimPrefix(u.Path, "/") diff --git a/scheme.go b/scheme.go index b3375ca..13c4072 100644 --- a/scheme.go +++ b/scheme.go @@ -166,7 +166,7 @@ func BaseSchemes() []Scheme { }, { "clickhouse", - GenFromURL("clickhouse://localhost:9000/"), 0, false, + GenClickhouse, TransportAny, false, []string{"ch"}, "", },