mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 13:34:32 +08:00
Support ClickHouse bulkcopy
This commit is contained in:
parent
3a39bf303f
commit
b075d1ca45
@ -1,37 +1,45 @@
|
|||||||
using ClickHouse;
|
using ClickHouse;
|
||||||
using ClickHouse.Client.ADO;
|
using ClickHouse.Client.ADO;
|
||||||
|
using ClickHouse.Client.Copy;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SqlSugar.ClickHouse
|
namespace SqlSugar.ClickHouse
|
||||||
{
|
{
|
||||||
public class ClickHouseFastBuilder : FastBuilder, IFastBuilder
|
public class ClickHouseFastBuilder : FastBuilder, IFastBuilder
|
||||||
{
|
{
|
||||||
|
|
||||||
public ClickHouseFastBuilder(EntityInfo entityInfo)
|
|
||||||
{
|
|
||||||
throw new NotSupportedException("NotSupportedException");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string UpdateSql { get; set; } = @"UPDATE {1} SET {0} FROM {2} AS TE WHERE {3}
|
|
||||||
";
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
||||||
{
|
{
|
||||||
await Task.FromResult(0);
|
var bulkCopy = GetBulkCopyInstance();
|
||||||
throw new NotSupportedException("NotSupportedException");
|
bulkCopy.DestinationTableName = dt.TableName;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await bulkCopy.WriteToServerAsync(dt,new CancellationToken());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CloseDb();
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
CloseDb();
|
||||||
|
return dt.Rows.Count;
|
||||||
}
|
}
|
||||||
|
public ClickHouseBulkCopy GetBulkCopyInstance()
|
||||||
private void BulkCopy(DataTable dt, string copyString, ClickHouseConnection conn, List<DbColumnInfo> columns)
|
|
||||||
{
|
{
|
||||||
throw new NotSupportedException("NotSupportedException");
|
ClickHouseBulkCopy copy;
|
||||||
|
copy = new ClickHouseBulkCopy((ClickHouseConnection)this.Context.Ado.Connection);
|
||||||
|
if (this.Context.Ado.Connection.State == ConnectionState.Closed)
|
||||||
|
{
|
||||||
|
this.Context.Ado.Connection.Open();
|
||||||
|
}
|
||||||
|
copy.BatchSize = 100000;
|
||||||
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ namespace SqlSugar
|
|||||||
return resultConnector;
|
return resultConnector;
|
||||||
case DbType.Dm:
|
case DbType.Dm:
|
||||||
return new DmFastBuilder();
|
return new DmFastBuilder();
|
||||||
|
case DbType.ClickHouse:
|
||||||
|
var resultConnectorClickHouse = InstanceFactory.CreateInstance<IFastBuilder>("SqlSugar.ClickHouse.ClickHouseFastBuilder");
|
||||||
|
resultConnectorClickHouse.CharacterSet = this.CharacterSet;
|
||||||
|
return resultConnectorClickHouse;
|
||||||
case DbType.Kdbndp:
|
case DbType.Kdbndp:
|
||||||
break;
|
break;
|
||||||
case DbType.Oscar:
|
case DbType.Oscar:
|
||||||
|
Loading…
Reference in New Issue
Block a user