using SqlSugar;
namespace NPin.Framework.SqlSugarCore.Abstractions;
public class DbConnOptions
{
///
/// 连接字符串 必填
///
public string? Url { get; set; }
///
/// 数据库类型
///
public DbType? DbType { get; set; }
///
/// 开启种子数据
///
public bool EnabledDbSeed { get; set; } = false;
///
/// 开启 CodeFirst 自动化表结构
///
public bool EnabledCodeFirst { get; set; } = false;
///
/// 开启sql日志
///
public bool EnabledSqlLog { get; set; } = true;
///
/// 实体程序集
///
public List? EntityAssembly { get; set; }
///
/// 开启读写分离
///
public bool EnabledReadWrite { get; set; } = false;
///
/// 读写分离
///
public List? ReadUrl { get; set; }
///
/// 开启Saas多租户
///
public bool EnabledSaasMultiTenancy { get; set; } = false;
///
/// 默认租户库连接,如果不填,那就是默认库的地址
///
public string? MasterSaasMultiTenancyUrl { get; set; }
///
/// Saas租户连接
///
public List? SaasMultiTenancy { get; set; }
public static string MasterTenantDbDefaultName = "Master";
public static string TenantDbDefaultName = "Default";
public SaasMultiTenancyOptions GetDefaultSaasMultiTenancy()
{
return new SaasMultiTenancyOptions { Name = TenantDbDefaultName, Url = Url };
}
public SaasMultiTenancyOptions? GetDefaultMasterSaasMultiTenancy()
{
if (EnabledSaasMultiTenancy == false)
{
return null;
}
if (string.IsNullOrEmpty(MasterSaasMultiTenancyUrl))
{
return new SaasMultiTenancyOptions { Name = MasterTenantDbDefaultName, Url = Url };
}
else
{
return new SaasMultiTenancyOptions()
{
Name = MasterTenantDbDefaultName,
Url = MasterSaasMultiTenancyUrl
};
}
}
}
public class SaasMultiTenancyOptions
{
///
/// 租户名称标识
///
public string Name { get; set; }
///
/// 连接Url
///
public string Url { get; set; }
}