mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-15 20:49:31 +08:00
Soris db CodeFirst support
This commit is contained in:
parent
9312b26feb
commit
6d26feb6fa
@ -508,6 +508,9 @@ namespace SqlSugar
|
||||
break;
|
||||
case DbType.Doris:
|
||||
config.DbType = DbType.MySql;
|
||||
if (this.CurrentConnectionConfig.MoreSettings == null)
|
||||
this.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings();
|
||||
this.CurrentConnectionConfig.MoreSettings.DatabaseModel = DbType.Doris;
|
||||
break;
|
||||
case DbType.TDengine:
|
||||
Check.Exception(SugarCompatible.IsFramework, "TDengine only support .net core");
|
||||
|
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
namespace SqlSugar
|
||||
{
|
||||
internal class DorisHelper
|
||||
{
|
||||
|
||||
public static bool IsDoris(ISqlSugarClient context)
|
||||
{
|
||||
return context.CurrentConnectionConfig?.MoreSettings?.DatabaseModel == DbType.Doris;
|
||||
}
|
||||
|
||||
public static string UpdateDorisSql(ISqlBuilder sqlBuilder,List<DbColumnInfo> columns, string sql)
|
||||
{
|
||||
var pk = columns.FirstOrDefault(it => it.IsPrimarykey);
|
||||
if (pk != null)
|
||||
{
|
||||
Check.ExceptionEasy(columns.Where(it => it.IsIdentity).Count() > 1, "Doris identity key no supported", "Doris不支持自增");
|
||||
Check.ExceptionEasy(columns.Where(it => it.IsPrimarykey).Count() > 1, "Doris Only one primary key is supported", "Doris只支持单主键");
|
||||
sql = sql.Replace("$PrimaryKey)", ")");
|
||||
var pkName = sqlBuilder.GetTranslationColumnName(pk.DbColumnName);
|
||||
sql += " \r\nENGINE=OLAP\r\nDUPLICATE KEY(" + pkName + ")\r\nDISTRIBUTED BY HASH(" + pkName + ") BUCKETS 1\r\nPROPERTIES (\r\n 'replication_num' = '1',\r\n 'storage_format' = 'DEFAULT'\r\n);\r\n\r\n";
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
}
|
||||
}
|
@ -442,6 +442,10 @@ WHERE EVENT_OBJECT_TABLE = '" + tableName + "'");
|
||||
}
|
||||
public override bool AddTableRemark(string tableName, string description)
|
||||
{
|
||||
if (DorisHelper.IsDoris(this.Context))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string sql = string.Format(this.AddTableRemarkSql, this.SqlBuilder.GetTranslationTableName(tableName), description);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
@ -464,6 +468,10 @@ WHERE EVENT_OBJECT_TABLE = '" + tableName + "'");
|
||||
primaryKeyInfo =string.Format( ", Primary key({0})",string.Join(",",columns.Where(it=>it.IsPrimarykey).Select(it=>this.SqlBuilder.GetTranslationColumnName(it.DbColumnName))));
|
||||
|
||||
}
|
||||
if (DorisHelper.IsDoris(this.Context))
|
||||
{
|
||||
sql = DorisHelper.UpdateDorisSql(this.SqlBuilder, columns, sql);
|
||||
}
|
||||
sql = sql.Replace("$PrimaryKey", primaryKeyInfo);
|
||||
this.Context.Ado.ExecuteCommand(sql);
|
||||
return true;
|
||||
@ -520,7 +528,14 @@ WHERE EVENT_OBJECT_TABLE = '" + tableName + "'");
|
||||
return tableString;
|
||||
}
|
||||
|
||||
|
||||
public override bool AddPrimaryKey(string tableName, string columnName)
|
||||
{
|
||||
if (DorisHelper.IsDoris(this.Context))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return base.AddPrimaryKey(tableName, columnName);
|
||||
}
|
||||
public override bool AddColumn(string tableName, DbColumnInfo columnInfo)
|
||||
{
|
||||
tableName = this.SqlBuilder.GetTranslationTableName(tableName);
|
||||
|
Loading…
Reference in New Issue
Block a user