Skip to content

Commit

Permalink
Add support for defaulting database, username, and password from envi…
Browse files Browse the repository at this point in the history
…ronment variables (#526)
  • Loading branch information
smbecker authored Sep 9, 2024
1 parent 8fae3f0 commit 4dd1179
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ClickHouse.Client/ADO/ClickHouseConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class ClickHouseConnection : DbConnection, IClickHouseConnection, IClonea
private Version serverVersion;
private string serverTimezone;

private string database = "default";
private string username;
private string password;
private string database = ClickHouseEnvironment.Database;
private string username = ClickHouseEnvironment.Username;
private string password = ClickHouseEnvironment.Password;
private string session;
private bool useServerTimezone;
private bool useCustomDecimals;
Expand Down
6 changes: 3 additions & 3 deletions ClickHouse.Client/ADO/ClickHouseConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public ClickHouseConnectionStringBuilder(string connectionString)

public string Database
{
get => GetStringOrDefault("Database", "default");
get => GetStringOrDefault("Database", ClickHouseEnvironment.Database);
set => this["Database"] = value;
}

public string Username
{
get => GetStringOrDefault("Username", "default");
get => GetStringOrDefault("Username", ClickHouseEnvironment.Username);
set => this["Username"] = value;
}

public string Password
{
get => GetStringOrDefault("Password", string.Empty);
get => GetStringOrDefault("Password", ClickHouseEnvironment.Password);
set => this["Password"] = value;
}

Expand Down
12 changes: 12 additions & 0 deletions ClickHouse.Client/ADO/ClickHouseEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace ClickHouse.Client.ADO;

internal static class ClickHouseEnvironment
{
public static string Database => Environment.GetEnvironmentVariable("CLICKHOUSE_DB") ?? "default";

public static string Username => Environment.GetEnvironmentVariable("CLICKHOUSE_USER") ?? "default";

public static string Password => Environment.GetEnvironmentVariable("CLICKHOUSE_PASSWORD") ?? string.Empty;
}

0 comments on commit 4dd1179

Please sign in to comment.