[Repository] 增加清空資料表 函式

This commit is contained in:
wanli 2023-01-03 22:29:29 +08:00
parent ba03adc2b5
commit 560ec58908
2 changed files with 43 additions and 0 deletions

View File

@ -888,5 +888,41 @@ namespace Repository.BaseRepository.Implement
} }
#endregion AddOneReturnId #endregion AddOneReturnId
#region TruncateTable ()
/// <summary>
/// 清空資料表資料
/// TRUNCATE TABLE {tableName}
/// </summary>
/// <param name="table_name"></param>
/// <returns></returns>
public virtual async Task TruncateTable(string table_name)
{
using (IDbConnection conn = GetDbConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = $"TRUNCATE TABLE {table_name}";
await conn.ExecuteAsync(sql, null, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
#endregion TruncateTable
} }
} }

View File

@ -181,5 +181,12 @@ namespace Repository.BaseRepository.Interface
/// <returns> /// <returns>
/// </returns> /// </returns>
Task<int> AddOneByCustomTableReturnId(Dictionary<string, object> dict, string Table_name, bool returnId = true); Task<int> AddOneByCustomTableReturnId(Dictionary<string, object> dict, string Table_name, bool returnId = true);
/// <summary>
/// 清空table資料
/// </summary>
/// <param name="table_name">資料表名稱</param>
/// <returns>
/// </returns>
Task TruncateTable(string table_name);
} }
} }