Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
YahuiWong committed Jun 9, 2021
1 parent bdbeef0 commit 2a837a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<RepositoryUrl>https://github.com/YahuiWong/Dapper.Contrib.BulkInsert.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>clickhouse,dapper,bulk,mysql,sqlserver</PackageTags>
<Version>0.1.0</Version>
<Version>0.1.5</Version>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseUrl>https://github.com/YahuiWong/Dapper.Contrib.BulkInsert/blob/master/LICENSE</PackageLicenseUrl>
<PackageId>Dapper.Contrib.BulkInsert</PackageId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ClickHouse.Ado" Version="1.3.1" />
<PackageReference Include="ClickHouse.Client" Version="3.1.0.379" />
</ItemGroup>
<ItemGroup>
Expand Down
9 changes: 3 additions & 6 deletions src/Dapper.Contrib.BulkInsert/SqlMapperExtensions.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ClickHouse.Client.ADO;
using ClickHouse.Client.Copy;
using Dapper;

namespace Dapper.Contrib.BulkInsert
{
Expand All @@ -18,7 +15,7 @@ public static partial class SqlMapperExtensions

/// <summary>
/// Inserts an entity into table "Ts" and returns identity id or number of inserted rows if inserting a list.
/// </summary>
/// </summary>
/// <param name="connection">Open SqlConnection</param>
/// <param name="entityToInsert">Entity to insert, can be list of entities</param>
/// <param name="commandTimeout">Number of seconds before command execution timeout</param>
Expand All @@ -39,7 +36,7 @@ public static async Task InsertBulkAsync<T>(this IDbConnection connection, IEnum
/// <param name="connection">Open SqlConnection</param>
/// <param name="entityToInsert">Entity to insert, can be list of entities</param>
/// <returns>Identity of inserted entity, or number of inserted rows if inserting a list</returns>
public static async Task InsertBulkAsync<T>(this ClickHouseConnection connection, IEnumerable<T> entityToInsert, int? commandTimeout = null)
public static async Task InsertBulkAsync<T>(this ClickHouse.Client.ADO.ClickHouseConnection connection, IEnumerable<T> entityToInsert, int? commandTimeout = null)
{

var wasClosed = connection.State == ConnectionState.Closed;
Expand Down Expand Up @@ -116,7 +113,7 @@ public static async Task InsertBulkAsync<T>(this ClickHouseConnection connection
rowList.Add(row);
}
}
using (var bulkCopy = new ClickHouseBulkCopy(connection)
using (var bulkCopy = new ClickHouse.Client.Copy.ClickHouseBulkCopy(connection)
{
DestinationTableName = name,
MaxDegreeOfParallelism = 2,
Expand Down
21 changes: 14 additions & 7 deletions src/Dapper.Contrib.BulkInsert/SqlMapperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
using System.Reflection;
using System.Text;
using System.Collections.Concurrent;
using System.Reflection.Emit;
using Dapper;
using ClickHouse.Client.ADO;
using ClickHouse.Client.Copy;


namespace Dapper.Contrib.BulkInsert
{
Expand Down Expand Up @@ -277,14 +274,24 @@ private static (string, DynamicParameters) GenerateBulkSql<T>(IDbConnection conn
{
if (property.PropertyType == typeof(DateTime))
{
var datetimevalue = Convert.ToDateTime(val);
if (property.GetCustomAttribute<DateAttribute>() != null)
{
parameters.Add(columnName, string.Format("{0:yyyy-MM-dd}", val));
parameters.Add(columnName, datetimevalue.Date, DbType.Date);
//sbParameterList.AppendFormat("'{0:yyyy-MM-dd}'", val);
}
else
{
parameters.Add(columnName, string.Format("{0:yyyy-MM-dd HH:mm:ss}", val));
parameters.Add(columnName, datetimevalue, DbType.DateTime);
//sbParameterList.AppendFormat("'{0:yyyy-MM-dd HH:mm:ss}'", val);
}
}
else if (property.PropertyType == typeof(Boolean))
{
var boolvalue = Convert.ToBoolean(val);

{
parameters.Add(columnName, boolvalue?1:0, DbType.Int32);
//sbParameterList.AppendFormat("'{0:yyyy-MM-dd HH:mm:ss}'", val);
}
}
Expand Down Expand Up @@ -338,7 +345,7 @@ public static void InsertBulk<T>(this IDbConnection connection, IEnumerable<T> e
/// <param name="connection">Open SqlConnection</param>
/// <param name="entityToInsert">Entity to insert, can be list of entities</param>
/// <returns>Identity of inserted entity, or number of inserted rows if inserting a list</returns>
public static void InsertBulk<T>(this ClickHouseConnection connection, IEnumerable<T> entityToInsert, int? commandTimeout = null)
public static void InsertBulk<T>(this ClickHouse.Client.ADO.ClickHouseConnection connection, IEnumerable<T> entityToInsert, int? commandTimeout = null)
{
InsertBulkAsync(connection, entityToInsert, commandTimeout).GetAwaiter().GetResult();
}
Expand Down

0 comments on commit 2a837a5

Please sign in to comment.