QuestDb support create split table

This commit is contained in:
sunkaixuan 2022-07-31 21:07:10 +08:00
parent 9fd461d508
commit 92af9e4e66
3 changed files with 29 additions and 1 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace SqlSugar
@ -31,6 +32,15 @@ namespace SqlSugar
}
}
columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
foreach (var propety in entityInfo.Type.GetProperties())
{
var timeAttr= propety.GetCustomAttribute<TimeDbSplitFieldAttribute>();
if (timeAttr != null)
{
var colName = columns.FirstOrDefault(it => it.PropertyName == propety.Name)?.DbColumnName;
tableName +=$"_TIMESTAMP({colName}) PARTITION BY {timeAttr.DateType} ";
}
}
this.Context.DbMaintenance.CreateTable(tableName, columns,true);
}
protected override DbColumnInfo EntityColumnToDbColumn(EntityInfo entityInfo, string tableName, EntityColumnInfo item)
@ -46,6 +56,7 @@ namespace SqlSugar
IsNullable = item.IsNullable,
DefaultValue = item.DefaultValue,
ColumnDescription = item.ColumnDescription,
PropertyName=item.PropertyName,
Length = item.Length
};
if (propertyType == UtilConstants.DecType)

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace SqlSugar
{
@ -370,6 +371,12 @@ namespace SqlSugar
}
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
{
var splitSql = "";
if (tableName.Contains("_TIMESTAMP("))
{
splitSql = Regex.Match(tableName,@"_TIMESTAMP\(.+$").Value;
tableName = tableName.Replace(splitSql, "");
}
if (columns.HasValue())
{
foreach (var item in columns)
@ -388,7 +395,7 @@ namespace SqlSugar
}
sql = sql.Replace("$PrimaryKey", primaryKeyInfo);
this.Context.Ado.ExecuteCommand(sql);
this.Context.Ado.ExecuteCommand(sql+ splitSql.TrimStart('_'));
return true;
}
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)

View File

@ -25,4 +25,14 @@ namespace SqlSugar
}
}
[AttributeUsage(AttributeTargets.Property, Inherited = true)]
public class TimeDbSplitFieldAttribute : Attribute
{
public DateType? DateType { get; set; }
public TimeDbSplitFieldAttribute(DateType type)
{
DateType = type;
}
}
}