添加ClickHouse数据库支持

This commit is contained in:
chenbo
2021-11-25 17:40:00 +08:00
parent e6f05aa24e
commit d085acc4e9
29 changed files with 2631 additions and 12 deletions

View File

@ -60,6 +60,7 @@ namespace FreeSql
/// 自定义适配器,访问任何数据库<para></para>
/// 注意:该类型不提供 DbFirst/CodeFirst 功能
/// </summary>
Custom
Custom,
ClickHouse
}
}

View File

@ -59,6 +59,10 @@ namespace FreeSql
providerType = Type.GetType("FreeSql.Firebird.FirebirdProvider`1,FreeSql.Provider.Firebird")?.MakeGenericType(connType);
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包FreeSql.Provider.Firebird.dll可前往 nuget 下载");
break;
case "ClickHouseConnection":
providerType = Type.GetType("FreeSql.ClickHouse.ClickHouseProvider`1,FreeSql.Provider.ClickHouse")?.MakeGenericType(connType);
if (providerType == null) throw new Exception("缺少 FreeSql 数据库实现包FreeSql.Provider.ClickHouse.dll可前往 nuget 下载");
break;
default:
throw new Exception("未实现");
}

View File

@ -495,6 +495,7 @@ JOIN {select._commonUtils.QuoteSqlName(tb.DbName)} a ON cte_tbc.cte_id = a.{sele
case DataType.SqlServer:
case DataType.OdbcSqlServer:
case DataType.Firebird:
case DataType.ClickHouse:
sql1ctePath = select._commonExpression.ExpressionWhereLambda(select._tables, Expression.Call(typeof(Convert).GetMethod("ToString", new Type[] { typeof(string) }), pathSelector?.Body), null, null, null);
break;
default:
@ -609,6 +610,7 @@ SELECT ");
{
case DataType.MySql:
case DataType.OdbcMySql:
case DataType.ClickHouse:
return that.OrderBy("rand()");
case DataType.SqlServer:
case DataType.OdbcSqlServer:

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45;net40</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net45;net40</TargetFrameworks>
<Version>2.6.100</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>FreeSql;ncc;YeXiangQin</Authors>

View File

@ -265,6 +265,11 @@ namespace FreeSql
if (type == null) throwNotFind("FreeSql.Provider.Custom.dll", "FreeSql.Custom.CustomProvider<>");
break;
case DataType.ClickHouse:
type = Type.GetType("FreeSql.ClickHouse.ClickHouseProvider`1,FreeSql.Provider.ClickHouse")?.MakeGenericType(typeof(TMark));
if (type == null) throwNotFind("FreeSql.Provider.ClickHouse.dll", "FreeSql.ClickHouse.ClickHouseProvider<>");
break;
default: throw new Exception("未指定 UseConnectionString 或者 UseConnectionFactory");
}
}

View File

@ -157,7 +157,7 @@ namespace FreeSql.Internal.CommonProvider
return this;
}
public string ToSql()
public virtual string ToSql()
{
if (_whereTimes <= 0) return null;
var sb = new StringBuilder().Append("DELETE FROM ").Append(_commonUtils.QuoteSqlName(TableRuleInvoke())).Append(" WHERE ").Append(_where);

View File

@ -445,7 +445,7 @@ namespace FreeSql.Internal.CommonProvider
_set.Append(", ").Append(_commonUtils.QuoteSqlName(col.Attribute.Name)).Append(" = ");
var colsql = _noneParameter ? _commonUtils.GetNoneParamaterSqlValue(_params, "u", col, col.Attribute.MapType, val) :
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, $"{_commonUtils.QuoteParamterName("p_")}{_params.Count}");
_commonUtils.QuoteWriteParamterAdapter(col.Attribute.MapType, _commonUtils.QuoteParamterName($"p_{_params.Count}"));
_set.Append(_commonUtils.RewriteColumn(col, colsql));
if (_noneParameter == false)
_commonUtils.AppendParamter(_params, null, col, col.Attribute.MapType, val);

View File

@ -54,7 +54,7 @@ namespace FreeSql.Internal
public abstract string NowUtc { get; }
public abstract string QuoteWriteParamterAdapter(Type type, string paramterName);
protected abstract string QuoteReadColumnAdapter(Type type, Type mapType, string columnName);
public string RewriteColumn(ColumnInfo col, string sql)
public virtual string RewriteColumn(ColumnInfo col, string sql)
{
if (string.IsNullOrWhiteSpace(col?.Attribute.RewriteSql) == false)
return string.Format(col.Attribute.RewriteSql, sql);