52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using Cocona;
|
|
using MesETL.Shared.Helper;
|
|
using Mesdb.Cli;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
var host = Host.CreateApplicationBuilder(args);
|
|
host.Configuration.AddCommandLine(args, new Dictionary<string, string>
|
|
{
|
|
{ "-s", "ConnectionString" },
|
|
{ "--ConnectionString", "ConnectionString" },
|
|
{ "-B", "Databases" },
|
|
{ "--Databases", "Databases" },
|
|
{ "-a", "All" },
|
|
{ "-c", "Command"},
|
|
{ "--Command", "Command" },
|
|
{ "--Sql", "Command" }
|
|
});
|
|
host.Build();
|
|
var connStr = host.Configuration.GetValue<string>("ConnectionString") ?? throw new ApplicationException("没有配置数据库连接字符串");
|
|
var databases = host.Configuration.GetValue<string>("Databases")?.Split(',').ToList() ?? throw new ApplicationException("没有配置数据库");
|
|
var all = host.Configuration.GetValue<bool>("All");
|
|
|
|
if (args.Length > 1 && args[0] == "count")
|
|
{
|
|
var result = await BatchDbExtensions.CountDatabasesAsync(connStr, databases);
|
|
if (all)
|
|
{
|
|
foreach (var (k, v) in result)
|
|
{
|
|
Console.WriteLine(k + ":");
|
|
Console.WriteLine(v.Select(pair => new { TABLE_NAME = pair.Key, COUNT = pair.Value }).ToMarkdownTable());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var allCount = result.Aggregate(new Dictionary<string, long>(), (dict, pair) =>
|
|
{
|
|
foreach (var (k, v) in pair.Value)
|
|
{
|
|
dict.AddOrUpdate(k, v, (key, num) => num + v);
|
|
}
|
|
return dict;
|
|
});
|
|
Console.WriteLine(allCount.Select(pair => new { TABLE_NAME = pair.Key, COUNT = pair.Value }).ToMarkdownTable());
|
|
}
|
|
}
|
|
|
|
if (args.Length > 1 && args[0] == "analyze")
|
|
{
|
|
await BatchDbExtensions.AnalyzeAllAsync(connStr, databases);
|
|
} |