Created
December 18, 2020 14:01
-
-
Save hodzanassredin/bd37d075ded09eaaa548179f6b9802d1 to your computer and use it in GitHub Desktop.
simple clickhouse https connector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//dont forget to sudo update-ca-certificates after certificate download from yandex cloud | |
public class ClickHouseConnection | |
{ | |
public string Host { get; } | |
public string User { get; } | |
public string Password { get; } | |
public string Db { get; } | |
public ClickHouseConnection(string host, string user, string password, string db) | |
{ | |
Host = host; | |
User = user; | |
Password = password; | |
Db = db; | |
} | |
public static async Task<string> QueryClickhouse(ClickHouseConnection connections, string query) | |
{ | |
var url = $"https://{connections.Host}:8443/?database={connections.Db}&query={query}"; | |
var client = new HttpClient(); | |
client.DefaultRequestHeaders.Add("X-ClickHouse-User", connections.User); | |
client.DefaultRequestHeaders.Add("X-ClickHouse-Key", connections.Password); | |
var res = await client.GetStringAsync(url); | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment