|
@@ -5,35 +5,29 @@ namespace DotNetCore.CAP.MySql.Test |
|
|
{ |
|
|
{ |
|
|
public static class ConnectionUtil |
|
|
public static class ConnectionUtil |
|
|
{ |
|
|
{ |
|
|
private const string DatabaseVariable = "Cap_MySql_DatabaseName"; |
|
|
|
|
|
private const string ConnectionStringTemplateVariable = "Cap_MySql_ConnectionStringTemplate"; |
|
|
|
|
|
|
|
|
private const string ConnectionStringTemplateVariable = "Cap_MySql_ConnectionString"; |
|
|
|
|
|
|
|
|
private const string MasterDatabaseName = "information_schema"; |
|
|
private const string MasterDatabaseName = "information_schema"; |
|
|
private const string DefaultDatabaseName = @"DotNetCore.CAP.MySql.Test"; |
|
|
|
|
|
|
|
|
private const string DefaultDatabaseName = "cap_test"; |
|
|
|
|
|
|
|
|
private const string DefaultConnectionStringTemplate = |
|
|
|
|
|
@"Server=localhost;Database={0};Uid=root;Pwd=123123;Allow User Variables=True;SslMode=none;"; |
|
|
|
|
|
|
|
|
private const string DefaultConnectionString = |
|
|
|
|
|
@"Server=localhost;Database=cap_test;Uid=root;Pwd=123123;Allow User Variables=True;SslMode=none;"; |
|
|
|
|
|
|
|
|
public static string GetDatabaseName() |
|
|
public static string GetDatabaseName() |
|
|
{ |
|
|
{ |
|
|
return Environment.GetEnvironmentVariable(DatabaseVariable) ?? DefaultDatabaseName; |
|
|
|
|
|
|
|
|
return DefaultDatabaseName; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static string GetMasterConnectionString() |
|
|
public static string GetMasterConnectionString() |
|
|
{ |
|
|
{ |
|
|
return string.Format(GetConnectionStringTemplate(), MasterDatabaseName); |
|
|
|
|
|
|
|
|
return GetConnectionString().Replace(DefaultDatabaseName, MasterDatabaseName); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static string GetConnectionString() |
|
|
public static string GetConnectionString() |
|
|
{ |
|
|
|
|
|
return string.Format(GetConnectionStringTemplate(), GetDatabaseName()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static string GetConnectionStringTemplate() |
|
|
|
|
|
{ |
|
|
{ |
|
|
return |
|
|
return |
|
|
Environment.GetEnvironmentVariable(ConnectionStringTemplateVariable) ?? |
|
|
Environment.GetEnvironmentVariable(ConnectionStringTemplateVariable) ?? |
|
|
DefaultConnectionStringTemplate; |
|
|
|
|
|
|
|
|
DefaultConnectionString; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static MySqlConnection CreateConnection(string connectionString = null) |
|
|
public static MySqlConnection CreateConnection(string connectionString = null) |
|
|