Browse Source

Synchronization code

pull/29/head
sunkaixuan 2 years ago
parent
commit
bb664be191
  1. 12
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs
  2. 8
      Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs
  3. 8
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs
  4. 2
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs
  5. 10
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs
  6. 4
      Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs
  7. 2
      Src/Asp.NetCore2/SqlSugar/Interface/ISqlSugarClient.cs
  8. 23
      Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs
  9. 23
      Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs
  10. 9
      Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs

12
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs

@ -833,6 +833,18 @@ namespace SqlSugar
{
return new SaveableProvider<T>(this, saveObject);
}
public StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName)
{
DataTable dt = this.Context.Utilities.DictionaryListToDataTable(dictionaryList);
dt.TableName = tableName;
return this.Context.Storageable(dt);
}
public StorageableDataTable Storageable(Dictionary<string, object> dictionary, string tableName)
{
DataTable dt = this.Context.Utilities.DictionaryListToDataTable(new List<Dictionary<string, object>>() { dictionary });
dt.TableName = tableName;
return this.Context.Storageable(dt);
}
public IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new()
{
this.InitMappingInfo<T>();

8
Src/Asp.NetCore2/SqlSugar/Abstract/SugarProvider/SqlSugarScopeProvider.cs

@ -566,6 +566,14 @@ namespace SqlSugar
{
return ScopedContext.SqlQueryable<T>(sql);
}
public StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName)
{
return ScopedContext.Storageable(dictionaryList, tableName);
}
public StorageableDataTable Storageable(Dictionary<string, object> dictionary, string tableName)
{
return ScopedContext.Storageable(dictionary, tableName);
}
public IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new()
{

8
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/DefaultDbMethod.cs

@ -681,5 +681,13 @@ namespace SqlSugar
model.Args[0].MemberName = name;
return AggregateSum(model);
}
public virtual string JsonListObjectAny(MethodCallExpressionModel model)
{
throw new NotImplementedException("Current database no support");
}
public virtual string JsonArrayAny(MethodCallExpressionModel model)
{
throw new NotImplementedException("Current database no support");
}
}
}

2
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/IDbMethods.cs

@ -100,5 +100,7 @@ namespace SqlSugar
string JsonLike(MethodCallExpressionModel model);
string Collate(MethodCallExpressionModel model);
string AggregateSumNoNull(MethodCallExpressionModel model);
string JsonListObjectAny(MethodCallExpressionModel model);
string JsonArrayAny(MethodCallExpressionModel model);
}
}

10
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/DbMethods/SqlFunc.cs

@ -256,5 +256,15 @@ namespace SqlSugar
public static DateTime Oracle_ToDate(string date,string format) { throw new NotSupportedException("Can only be used in expressions"); }
public static string Oracle_ToChar(DateTime date, string format) { throw new NotSupportedException("Can only be used in expressions"); }
public static int SqlServer_DateDiff(string dateType,DateTime date1,DateTime date2) { throw new NotSupportedException("Can only be used in expressions"); }
public static bool JsonListObjectAny(object jsonListObject, string fieldName, object value)
{
throw new NotSupportedException("Can only be used in expressions");
}
public static bool JsonArrayAny(object jsonArray,object arrayValue)
{
throw new NotSupportedException("Can only be used in expressions");
}
}
}

4
Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/MethodCallExpressionResolve_Helper.cs

@ -752,6 +752,10 @@ namespace SqlSugar
return this.Context.DbMehtods.Collate(model);
case "AggregateSumNoNull":
return this.Context.DbMehtods.AggregateSumNoNull(model);
case "JsonListObjectAny":
return this.Context.DbMehtods.JsonListObjectAny(model);
case "JsonArrayAny":
return this.Context.DbMehtods.JsonArrayAny(model);
default:
break;
}

2
Src/Asp.NetCore2/SqlSugar/Interface/ISqlSugarClient.cs

@ -137,6 +137,8 @@ namespace SqlSugar
#endregion
#region Saveable
StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName);
StorageableDataTable Storageable(Dictionary<string, object> dictionary, string tableName);
IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new();
IStorageable<T> Storageable<T>(T data) where T : class, new();
StorageableDataTable Storageable(DataTable data);

23
Src/Asp.NetCore2/SqlSugar/Realization/MySql/SqlBuilder/MySqlExpressionContext.cs

@ -217,5 +217,28 @@ namespace SqlSugar
{
return $"{memberName1}->\"$.{memberName2}\"";
}
public override string JsonArrayAny(MethodCallExpressionModel model)
{
if (UtilMethods.IsNumber(model.Args[1].MemberValue.GetType().Name))
{
return $"JSON_CONTAINS({model.Args[0].MemberName}, '{model.Args[1].MemberValue}')";
}
else
{
return $"JSON_CONTAINS({model.Args[0].MemberName}, '\"{model.Args[1].MemberValue.ObjToStringNoTrim().ToSqlFilter()}\"')";
}
}
public override string JsonListObjectAny(MethodCallExpressionModel model)
{
if (UtilMethods.IsNumber(model.Args[2].MemberValue.GetType().Name))
{
return $"JSON_CONTAINS({model.Args[0].MemberName},'{{\"{model.Args[1].MemberValue}\":{model.Args[2].MemberValue}}}')";
}
else
{
return $"JSON_CONTAINS({model.Args[0].MemberName},'{{\"{model.Args[1].MemberValue}\":\"{model.Args[2].MemberValue.ObjToStringNoTrim().ToSqlFilter()}\"}}')";
}
}
}
}

23
Src/Asp.NetCore2/SqlSugar/Realization/PostgreSQL/SqlBuilder/PostgreSQLExpressionContext.cs

@ -443,5 +443,28 @@ namespace SqlSugar
//var parameter1 = model.Args[1];
return $" ({parameter.MemberName}::json) ";
}
public override string JsonArrayAny(MethodCallExpressionModel model)
{
if (UtilMethods.IsNumber(model.Args[1].MemberValue.GetType().Name))
{
return $"{model.Args[0].MemberName}::jsonb @> '[{model.Args[1].MemberValue.ObjToStringNoTrim().ToSqlFilter()}]'::jsonb";
}
else
{
return $"{model.Args[0].MemberName}::jsonb @> '[\"{model.Args[1].MemberValue}\"]'::jsonb";
}
}
public override string JsonListObjectAny(MethodCallExpressionModel model)
{
if (UtilMethods.IsNumber(model.Args[2].MemberValue.GetType().Name))
{
return $"{model.Args[0].MemberName}::jsonb @> '[{{\"{model.Args[1].MemberValue}\":{model.Args[2].MemberValue}}}]'::jsonb";
}
else
{
return $"{model.Args[0].MemberName}::jsonb @> '[{{\"{model.Args[1].MemberValue}\":\"{model.Args[2].MemberValue.ObjToStringNoTrim().ToSqlFilter()}\"}}]'::jsonb";
}
}
}
}

9
Src/Asp.NetCore2/SqlSugar/SqlSugarScope.cs

@ -569,7 +569,14 @@ namespace SqlSugar
{
return ScopedContext.SqlQueryable<T>(sql);
}
public StorageableDataTable Storageable(List<Dictionary<string, object>> dictionaryList, string tableName)
{
return ScopedContext.Storageable(dictionaryList, tableName);
}
public StorageableDataTable Storageable(Dictionary<string, object> dictionary, string tableName)
{
return ScopedContext.Storageable(dictionary, tableName);
}
public IStorageable<T> Storageable<T>(List<T> dataList) where T : class, new()
{
return ScopedContext.Storageable(dataList);

Loading…
Cancel
Save