Synchronization code

This commit is contained in:
sunkaixuan 2024-05-09 17:39:09 +08:00
parent e3f5ba7cca
commit 3d494f40b8
4 changed files with 18 additions and 3 deletions

View File

@ -557,7 +557,11 @@ namespace SqlSugar
}
return this;
}
public IInsertable<T> PostgreSQLConflictNothing(string[] columns)
{
this.InsertBuilder.ConflictNothing = columns;
return this;
}
public IInsertable<T> MySqlIgnore()
{
this.InsertBuilder.MySqlIgnore = true;

View File

@ -133,6 +133,7 @@ namespace SqlSugar
public bool MySqlIgnore { get; internal set; }
public bool IsWithAttr { get; internal set; }
public string[] ConflictNothing { get; set; }
public virtual ExpressionResult GetExpressionValue(Expression expression, ResolveExpressType resolveType)
{

View File

@ -64,6 +64,7 @@ namespace SqlSugar
SplitInsertable<T> SplitTable(SplitType splitType);
void AddQueue();
IInsertable<T> MySqlIgnore();
IInsertable<T> PostgreSQLConflictNothing(string[] columns);
IInsertable<T> OffIdentity();
IInsertable<T> OffIdentity(bool isSetOn);
InsertablePage<T> PageSize(int pageSize);

View File

@ -49,7 +49,7 @@ namespace SqlSugar
{
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it =>base.GetDbColumn(it, Builder.SqlParameterKeyWord + it.DbColumnName)));
ActionMinDate();
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
return GetIgnoreSql(string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString));
}
else
{
@ -116,7 +116,7 @@ namespace SqlSugar
pageIndex++;
batchInsetrSql.Remove(batchInsetrSql.Length - 1,1).Append("\r\n;\r\n");
}
return batchInsetrSql.ToString();
return GetIgnoreSql(batchInsetrSql.ToString());
}
}
@ -182,6 +182,15 @@ namespace SqlSugar
{
return "'" + ((DateTimeOffset)value).ToString("o") + "'";
}
private string GetIgnoreSql(string sql)
{
if (this.ConflictNothing?.Any() == true)
{
sql = sql.Replace(";", $" ON CONFLICT ({string.Join(",", this.ConflictNothing)}) DO NOTHING;");
}
return sql;
}
}
}