mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 12:47:57 +08:00
Support QuestDb bulkCopy
This commit is contained in:
parent
38ee69765f
commit
2fe32a1a25
@ -33,32 +33,10 @@ namespace SqlSugar
|
|||||||
//}
|
//}
|
||||||
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
||||||
{
|
{
|
||||||
List<string> lsColNames = new List<string>();
|
Check.ExceptionEasy(
|
||||||
for (int i = 0; i < dt.Columns.Count; i++)
|
"Nuget install: SqlSugar.QuestDb.RestAPI, use: await db.RestApi().BulkCopyAsync(list)",
|
||||||
{
|
"Nuget安装:SqlSugar.QuestDb.RestAPI ,QuestDb中请使用:await db.RestApi().BulkCopyAsync(list) 注意是db.RestApi()不是db.Fastest");
|
||||||
lsColNames.Add($"\"{dt.Columns[i].ColumnName}\"");
|
return await Task.FromResult(0);
|
||||||
}
|
|
||||||
string copyString = $"COPY {dt.TableName} ( {string.Join(",", lsColNames) } ) FROM STDIN (FORMAT BINARY)";
|
|
||||||
NpgsqlConnection conn = (NpgsqlConnection)this.Context.Ado.Connection;
|
|
||||||
var columns = this.Context.DbMaintenance.GetColumnInfosByTableName(this.entityInfo.DbTableName);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var identityColumnInfo = this.entityInfo.Columns.FirstOrDefault(it => it.IsIdentity);
|
|
||||||
if (identityColumnInfo != null)
|
|
||||||
{
|
|
||||||
throw new Exception("PgSql bulkcopy no support identity");
|
|
||||||
}
|
|
||||||
BulkCopy(dt, copyString, conn, columns);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
base.CloseDb();
|
|
||||||
}
|
|
||||||
return await Task.FromResult(dt.Rows.Count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BulkCopy(DataTable dt, string copyString, NpgsqlConnection conn, List<DbColumnInfo> columns)
|
private void BulkCopy(DataTable dt, string copyString, NpgsqlConnection conn, List<DbColumnInfo> columns)
|
||||||
|
Loading…
Reference in New Issue
Block a user