mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 16:18:47 +08:00
QuestDb support create split table
This commit is contained in:
parent
9fd461d508
commit
92af9e4e66
@ -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
|
namespace SqlSugar
|
||||||
@ -31,6 +32,15 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
columns = columns.OrderBy(it => it.IsPrimarykey ? 0 : 1).ToList();
|
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);
|
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)
|
||||||
@ -46,6 +56,7 @@ namespace SqlSugar
|
|||||||
IsNullable = item.IsNullable,
|
IsNullable = item.IsNullable,
|
||||||
DefaultValue = item.DefaultValue,
|
DefaultValue = item.DefaultValue,
|
||||||
ColumnDescription = item.ColumnDescription,
|
ColumnDescription = item.ColumnDescription,
|
||||||
|
PropertyName=item.PropertyName,
|
||||||
Length = item.Length
|
Length = item.Length
|
||||||
};
|
};
|
||||||
if (propertyType == UtilConstants.DecType)
|
if (propertyType == UtilConstants.DecType)
|
||||||
|
@ -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
|
namespace SqlSugar
|
||||||
{
|
{
|
||||||
@ -370,6 +371,12 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public override bool CreateTable(string tableName, List<DbColumnInfo> columns, bool isCreatePrimaryKey = true)
|
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())
|
if (columns.HasValue())
|
||||||
{
|
{
|
||||||
foreach (var item in columns)
|
foreach (var item in columns)
|
||||||
@ -388,7 +395,7 @@ namespace SqlSugar
|
|||||||
|
|
||||||
}
|
}
|
||||||
sql = sql.Replace("$PrimaryKey", primaryKeyInfo);
|
sql = sql.Replace("$PrimaryKey", primaryKeyInfo);
|
||||||
this.Context.Ado.ExecuteCommand(sql);
|
this.Context.Ado.ExecuteCommand(sql+ splitSql.TrimStart('_'));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)
|
protected override string GetCreateTableSql(string tableName, List<DbColumnInfo> columns)
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user