vengine初步实现增删改查
This commit is contained in:
@@ -1,10 +1,41 @@
|
||||
using JNPF.Logging;
|
||||
using Mapster;
|
||||
using SqlSugar;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
namespace Tnb.Vengine.DataAccess;
|
||||
|
||||
public class SugarHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建SugarClient实例
|
||||
/// </summary>
|
||||
public static ISqlSugarClient CreateSugarClient(string dbCode, string dbType, string dbConnection, Action<ConnectionConfig>? configConnection = null, Action<ISqlSugarClient>? configSugar = null)
|
||||
{
|
||||
var config = new ConnectionConfig
|
||||
{
|
||||
ConnectionString = dbConnection,
|
||||
DbType = dbType.Adapt<DbType>(),
|
||||
IsAutoCloseConnection = true,
|
||||
ConfigId = dbCode,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
IsAutoRemoveDataCache = true, // 自动清理缓存
|
||||
IsAutoToUpper = false,
|
||||
PgSqlIsAutoToLower = false,
|
||||
DisableNvarchar = true
|
||||
},
|
||||
};
|
||||
configConnection?.Invoke(config);
|
||||
var sugar = new SqlSugarScope(config, configSugar == null ? ConfigSugar : configSugar);
|
||||
return sugar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SqlSugar默认配置
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
public static void ConfigSugar(ISqlSugarClient db)
|
||||
{
|
||||
// 设置超时时间
|
||||
@@ -31,4 +62,12 @@ public class SugarHelper
|
||||
Log.Error(UtilMethods.GetSqlString(db.CurrentConnectionConfig.DbType, ex.Sql, (SugarParameter[])ex.Parametres));
|
||||
};
|
||||
}
|
||||
|
||||
public static void CustomSnowId()
|
||||
{
|
||||
StaticConfig.CustomSnowFlakeFunc = () =>
|
||||
{
|
||||
return YitIdHelper.NextId();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user