测试ClickHouse Bool映射插入

This commit is contained in:
d4ilys 2023-11-21 09:39:34 +08:00
parent dc73a1571a
commit 3528c01c5b
3 changed files with 94 additions and 2 deletions

View File

@ -8,11 +8,14 @@ using System.Diagnostics;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using FreeSql.DataAnnotations; using FreeSql.DataAnnotations;
using Xunit; using Xunit;
using Xunit.Abstractions;
namespace FreeSql.Tests.ClickHouse namespace FreeSql.Tests.ClickHouse
{ {
public class ClickHouseTest2 public class ClickHouseTest2
{ {
private static IFreeSql fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse, private static IFreeSql fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
"Host=127.0.0.1;Port=8123;Database=test;Compress=True;Min Pool Size=1") "Host=127.0.0.1;Port=8123;Database=test;Compress=True;Min Pool Size=1")
.UseMonitorCommand(cmd => Console.WriteLine($"线程:{cmd.CommandText}\r\n")) .UseMonitorCommand(cmd => Console.WriteLine($"线程:{cmd.CommandText}\r\n"))
@ -29,6 +32,7 @@ namespace FreeSql.Tests.ClickHouse
{ {
fsql.CodeFirst.SyncStructure(typeof(PositionInfoModel)); fsql.CodeFirst.SyncStructure(typeof(PositionInfoModel));
} }
[Fact] [Fact]
public void Issuse1587TestOnePrimary() public void Issuse1587TestOnePrimary()
{ {

View File

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FreeSql.DataAnnotations;
using Xunit;
using Xunit.Abstractions;
namespace FreeSql.Tests.ClickHouse
{
public class ClickHouseTest3
{
private static ITestOutputHelper _output;
private static IFreeSql _fsql;
public ClickHouseTest3(ITestOutputHelper output)
{
_output = output;
_fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
"Host=192.168.1.123;Port=8123;Database=test;Compress=True;Min Pool Size=1")
.UseMonitorCommand(cmd => _output.WriteLine($"线程:{cmd.CommandText}\r\n"))
.UseNoneCommandParameter(false)
.Build();
}
/// <summary>
/// 测试bool类型映射
/// </summary>
[Fact]
public void TestBoolMappingSync()
{
_fsql.CodeFirst.SyncStructure(typeof(BoolMappingTest));
}
/// <summary>
/// 测试bool类型映射
/// </summary>
[Fact]
public void TestBoolMappingInsert()
{
_fsql.Insert(new BoolMappingTest
{
Name = "Tom",
Age = 20,
Id = Guid.NewGuid().ToString(),
IsDelete = true,
IsEnable = true
}).ExecuteAffrows();
_fsql.Insert(new BoolMappingTest
{
Name = "Jess",
Age = 21,
Id = Guid.NewGuid().ToString(),
IsDelete = true,
IsEnable = false
}).ExecuteAffrows();
_fsql.Insert(new BoolMappingTest
{
Name = "Daily",
Age = 22,
Id = Guid.NewGuid().ToString(),
IsDelete = true,
IsEnable = null
}).ExecuteAffrows();
}
}
[Table(Name = "table_test_bool")]
public class BoolMappingTest
{
[Column(IsPrimary = true, Name = "id")]
public string Id { set; get; }
[Column(Name = "name")] public string Name { get; set; }
[Column(Name = "age")] public int Age { get; set; }
[Column(Name = "is_delete")] public bool IsDelete { get; set; }
[Column(Name = "is_enable")] public bool? IsEnable { get; set; }
}
}

View File

@ -43,8 +43,9 @@ namespace FreeSql.ClickHouse
if (col.DbScale != 0) ret.Scale = col.DbScale; if (col.DbScale != 0) ret.Scale = col.DbScale;
break; break;
} }
if (value is bool) //直接使用Bool
ret.Value = (bool)value ? 1 : 0; //if (value is bool)
// ret.Value = (bool)value ? 1 : 0;
} }
_params?.Add(ret); _params?.Add(ret);
return ret; return ret;