mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-10-15 18:55:07 +08:00
Clickhouse support createable engine
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace SqlSugar.ClickHouse
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
|
||||||
|
public class CKTable : Attribute
|
||||||
|
{
|
||||||
|
public string engineValue { get; set; }
|
||||||
|
public CKTable(string engineValue)
|
||||||
|
{
|
||||||
|
this.engineValue = engineValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SqlSugar.ClickHouse
|
namespace SqlSugar.ClickHouse
|
||||||
@@ -40,6 +41,10 @@ namespace SqlSugar.ClickHouse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
|
columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
|
||||||
|
if (entityInfo.Type.GetCustomAttribute<CKTable>() != null)
|
||||||
|
{
|
||||||
|
tableName = (tableName + UtilConstants.ReplaceKey + entityInfo.Type.GetCustomAttribute<CKTable>().engineValue);
|
||||||
|
}
|
||||||
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
|
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
|
||||||
}
|
}
|
||||||
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SqlSugar.ClickHouse
|
namespace SqlSugar.ClickHouse
|
||||||
{
|
{
|
||||||
@@ -338,6 +339,14 @@ namespace SqlSugar.ClickHouse
|
|||||||
}
|
}
|
||||||
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)
|
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)
|
||||||
{
|
{
|
||||||
|
string engineEq = null;
|
||||||
|
if (tableName.Contains(UtilConstants.ReplaceKey))
|
||||||
|
{
|
||||||
|
var tableInfos = Regex.Split(tableName, UtilConstants.ReplaceKey);
|
||||||
|
tableName = tableInfos.First();
|
||||||
|
engineEq = tableInfos.Last();
|
||||||
|
}
|
||||||
|
|
||||||
List<string> columnArray = new List<string>();
|
List<string> columnArray = new List<string>();
|
||||||
Check.Exception(columns.IsNullOrEmpty(), "No columns found ");
|
Check.Exception(columns.IsNullOrEmpty(), "No columns found ");
|
||||||
var pkName = "";
|
var pkName = "";
|
||||||
@@ -365,7 +374,11 @@ namespace SqlSugar.ClickHouse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName.ToLower(isLower)), string.Join(",\r\n", columnArray));
|
string tableString = string.Format(this.CreateTableSql, this.SqlBuilder.GetTranslationTableName(tableName.ToLower(isLower)), string.Join(",\r\n", columnArray));
|
||||||
if (pkName.HasValue())
|
if (engineEq.HasValue())
|
||||||
|
{
|
||||||
|
tableString += (" "+ engineEq);
|
||||||
|
}
|
||||||
|
else if (pkName.HasValue())
|
||||||
{
|
{
|
||||||
pkName = this.SqlBuilder.GetTranslationColumnName(pkName);
|
pkName = this.SqlBuilder.GetTranslationColumnName(pkName);
|
||||||
tableString += $"ENGINE = MergeTree() ORDER BY ( {pkName} ) PRIMARY KEY {pkName} SETTINGS index_granularity = 8192";
|
tableString += $"ENGINE = MergeTree() ORDER BY ( {pkName} ) PRIMARY KEY {pkName} SETTINGS index_granularity = 8192";
|
||||||
|
Reference in New Issue
Block a user