mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2026-02-27 06:03:09 +08:00
Code optimization
This commit is contained in:
@@ -1,46 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public abstract partial class DbMaintenanceProvider : IDbMaintenance
|
||||
{
|
||||
protected abstract string GetViewInfoListSql { get; }
|
||||
protected abstract string GetTableInfoListSql { get; }
|
||||
protected abstract string GetColumnInfosByTableNameSql { get; }
|
||||
protected abstract string AddColumnToTableSql { get; }
|
||||
protected abstract string BackupDataBaseSql { get; }
|
||||
protected abstract string CreateTableSql { get; }
|
||||
protected abstract string TruncateTableSql { get; }
|
||||
|
||||
public SqlSugarClient Context { get; set; }
|
||||
#region DML
|
||||
public List<DbTableInfo> GetViewInfoList()
|
||||
{
|
||||
string key = "DbMaintenanceProvider.GetViewInfoList";
|
||||
var result= GetListOrCache<DbTableInfo>(key, this.GetViewInfoListSql);
|
||||
var result = GetListOrCache<DbTableInfo>(key, this.GetViewInfoListSql);
|
||||
foreach (var item in result)
|
||||
{
|
||||
item.DbObjectType = DbObjectType.View;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<DbTableInfo> GetTableInfoList()
|
||||
{
|
||||
string key = "DbMaintenanceProvider.GetTableInfoList";
|
||||
var result= GetListOrCache<DbTableInfo>(key, this.GetTableInfoListSql);
|
||||
var result = GetListOrCache<DbTableInfo>(key, this.GetTableInfoListSql);
|
||||
foreach (var item in result)
|
||||
{
|
||||
item.DbObjectType = DbObjectType.Table;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual List<DbColumnInfo> GetColumnInfosByTableName(string tableName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(tableName)) return new List<DbColumnInfo>();
|
||||
string key = "DbMaintenanceProvider.GetColumnInfosByTableName." + tableName.ToLower();
|
||||
return GetListOrCache<DbColumnInfo>(key,string.Format(this.GetColumnInfosByTableNameSql,tableName));
|
||||
return GetListOrCache<DbColumnInfo>(key, string.Format(this.GetColumnInfosByTableNameSql, tableName));
|
||||
}
|
||||
|
||||
public virtual List<string> GetIsIdentities(string tableName)
|
||||
@@ -54,15 +48,13 @@ namespace SqlSugar
|
||||
var result = GetColumnInfosByTableName(tableName).Where(it => it.IsPrimarykey).ToList();
|
||||
return result.Select(it => it.DbColumnName).ToList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DDL
|
||||
public bool AddColumnToTable(string tableName, DbColumnInfo column)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public bool BackupDataBase()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual bool CreateTable(string tableName, List<DbColumnInfo> columns)
|
||||
{
|
||||
@@ -72,10 +64,16 @@ namespace SqlSugar
|
||||
|
||||
public virtual bool TruncateTable(string tableName)
|
||||
{
|
||||
this.Context.Ado.ExecuteCommand(string.Format(this.TruncateTableSql,tableName));
|
||||
this.Context.Ado.ExecuteCommand(string.Format(this.TruncateTableSql, tableName));
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool BackupDataBase()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
private List<T> GetListOrCache<T>(string cacheKey, string sql)
|
||||
{
|
||||
27
SqlSugar/Abstract/DbMaintenanceProvider/Properties.cs
Normal file
27
SqlSugar/Abstract/DbMaintenanceProvider/Properties.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
namespace SqlSugar
|
||||
{
|
||||
public abstract partial class DbMaintenanceProvider : IDbMaintenance
|
||||
{
|
||||
#region Context
|
||||
public SqlSugarClient Context { get; set; }
|
||||
#endregion
|
||||
|
||||
#region DML
|
||||
protected abstract string GetViewInfoListSql { get; }
|
||||
protected abstract string GetTableInfoListSql { get; }
|
||||
protected abstract string GetColumnInfosByTableNameSql { get; }
|
||||
#endregion
|
||||
|
||||
#region DDL
|
||||
protected abstract string AddColumnToTableSql { get; }
|
||||
protected abstract string BackupDataBaseSql { get; }
|
||||
protected abstract string CreateTableSql { get; }
|
||||
protected abstract string TruncateTableSql { get; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -7,31 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class SqlServerDbMaintenance : DbMaintenanceProvider
|
||||
{
|
||||
protected override string AddColumnToTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALERT TABLE {0} ADD {1} {2} {3}";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string BackupDataBaseSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string CreateTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"CREATE TABLE {0}
|
||||
{1}";
|
||||
}
|
||||
}
|
||||
|
||||
#region DML
|
||||
protected override string GetColumnInfosByTableNameSql
|
||||
{
|
||||
get
|
||||
@@ -78,7 +54,6 @@ namespace SqlSugar
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetTableInfoListSql
|
||||
{
|
||||
get
|
||||
@@ -88,7 +63,6 @@ namespace SqlSugar
|
||||
LEFT JOIN sys.extended_properties as tbp ON s.id=tbp.major_id and tbp.minor_id=0 WHERE s.xtype IN('U')";
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetViewInfoListSql
|
||||
{
|
||||
get
|
||||
@@ -98,13 +72,38 @@ namespace SqlSugar
|
||||
LEFT JOIN sys.extended_properties as tbp ON s.id=tbp.major_id and tbp.minor_id=0 WHERE s.xtype IN('V')";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DDL
|
||||
protected override string AddColumnToTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "ALERT TABLE {0} ADD {1} {2} {3}";
|
||||
}
|
||||
}
|
||||
protected override string BackupDataBaseSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
protected override string CreateTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"CREATE TABLE {0}
|
||||
{1}";
|
||||
}
|
||||
}
|
||||
protected override string TruncateTableSql
|
||||
{
|
||||
get
|
||||
{
|
||||
return "TRUNCATE TABLE {0}";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@
|
||||
<Compile Include="Abstract\DbBindProvider\IDataRecordExtensions.cs" />
|
||||
<Compile Include="Abstract\DbFirstProvider\DbFirstProvider.cs" />
|
||||
<Compile Include="Abstract\DbFirstProvider\DbFirstTemplate.cs" />
|
||||
<Compile Include="Abstract\DbMaintenanceProvider\DbMaintenanceProvider.cs" />
|
||||
<Compile Include="Abstract\DbMaintenanceProvider\Methods.cs" />
|
||||
<Compile Include="Abstract\DbMaintenanceProvider\Properties.cs" />
|
||||
<Compile Include="Abstract\AdoProvider\AdoProvider.cs" />
|
||||
<Compile Include="Abstract\EntityProvider\EntityProvider.cs" />
|
||||
<Compile Include="Abstract\InsertableProvider\InsertableProvider.cs" />
|
||||
|
||||
Reference in New Issue
Block a user