using MesETL.App.HostedServices;
namespace MesETL.App.Options;
public class DatabaseOutputOptions
{
///
/// 输出数据库的连接字符串
///
public string? ConnectionString { get; set; }
///
/// MySql max_allowed_packet变量值大小
///
public int MaxAllowedPacket { get; set; } = 32 * 1024 * 1024;
///
/// 每次Insert提交的数据量
///
public int FlushCount { get; set; } = 10000;
///
/// 每个数据库最大提交任务数
///
public int MaxDatabaseOutputTask { get; set; } = 4;
///
/// 将json列作为16进制格式输出(0x前缀)
///
public bool TreatJsonAsHex { get; set; } = true;
///
/// 不对某些表进行输出
///
public string[] NoOutput { get; set; } = [];
///
/// 当某张表的键出现重复时,在输出时使用ON DUPLICATE KEY UPDATE更新该条记录
/// 表名为键,更新的字段为值
///
///
/// {
/// // 当order_data_parts表的键出现重复时,使用ON DUPLICATE KEY UPDATE更新已存在记录的CompanyID为新插入记录的值
/// "order_data_parts": "CompanyID = new.CompanyID"
/// }
///
///
///
public Dictionary? ForUpdate { get; set; }
///
/// 配置导入数据的特殊列,请在代码中配置
///
public Dictionary ColumnTypeConfig { get; set; } = new(); // "table.column" -> type
///
/// 所有数据都输出完毕时的事件,请在代码中配置
///
public Action? OutputFinished { get; set; }
public ColumnType GetColumnType(string table, string column)
{
return ColumnTypeConfig.GetValueOrDefault(string.Concat(table, ".", column), ColumnType.UnDefine);
}
public bool TryGetForUpdate(string table, out string? forUpdate)
{
forUpdate = null;
if (ForUpdate is null || !ForUpdate.TryGetValue(table, out forUpdate))
return false;
return true;
}
}