-
Notifications
You must be signed in to change notification settings - Fork 860
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1936 from d4ilys/master
增加TDengine支持
- Loading branch information
Showing
29 changed files
with
3,074 additions
and
4 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
FreeSql.Tests/FreeSql.Tests.Provider.TDengine/FreeSql.Tests.Provider.TDengine.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="xunit" Version="2.5.3" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Providers\FreeSql.Provider.TDengine\FreeSql.Provider.TDengine.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |
104 changes: 104 additions & 0 deletions
104
FreeSql.Tests/FreeSql.Tests.Provider.TDengine/TDengine/TDengineAdo/TDengineAdoTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System; | ||
using FreeSql.Tests.Provider.TDengine.TDengine.Tables; | ||
using Xunit; | ||
|
||
namespace FreeSql.Tests.Provider.TDengine.TDengine.TDengineAdo | ||
{ | ||
public class TDengineAdoTest | ||
{ | ||
IFreeSql fsql => g.tdengine; | ||
|
||
[Fact] | ||
void CodeFirstTest() | ||
{ | ||
fsql.CodeFirst.SyncStructure<D1001>(); | ||
fsql.CodeFirst.SyncStructure<D1002>(); | ||
fsql.CodeFirst.SyncStructure<Users>(); | ||
} | ||
|
||
[Fact] | ||
void InsertTest() | ||
{ | ||
var insertAffrows = fsql.Insert(new D1001() | ||
{ | ||
Ts = DateTime.Now, | ||
Current = 1, | ||
Voltage = 1, | ||
Describe = "D10021" | ||
} | ||
).ExecuteAffrows(); | ||
|
||
var insertAffrows2 = fsql.Insert(new D1001() | ||
{ | ||
Ts = DateTime.Now, | ||
Current = 1, | ||
Voltage = 1, | ||
Describe = "D10021" | ||
} | ||
).ExecuteAffrows(); | ||
|
||
var batchInsertAffrows = fsql.Insert(new List<D1002>() | ||
{ | ||
new D1002() | ||
{ | ||
Ts = DateTime.Now, | ||
Current = 6, | ||
Voltage = 6, | ||
Describe = "D10026" | ||
}, | ||
new D1002() | ||
{ | ||
Ts = DateTime.Now, | ||
Current = 3, | ||
Voltage = 3, | ||
Describe = "D10023" | ||
}, | ||
new D1002() | ||
{ | ||
Ts = DateTime.Now, | ||
Current = 4, | ||
Voltage = 4, | ||
Describe = "D10024" | ||
} | ||
} | ||
).ExecuteAffrows(); | ||
} | ||
|
||
[Fact] | ||
void SelectTest() | ||
{ | ||
var subList = fsql.Select<D1001>().ToList(d => new | ||
{ | ||
GroupId = d.GroupId | ||
}); | ||
|
||
var superMetersList = fsql.Select<Meters>().ToList(); | ||
} | ||
|
||
[Fact] | ||
void WhereSelectTest() | ||
{ | ||
var list = fsql.Select<Meters>().Where(d => d.GroupId == 2).ToList(); | ||
} | ||
|
||
[Fact] | ||
void DeleteTest() | ||
{ | ||
var startTime = DateTime.Parse("2024-11-30T02:33:52.308+00:00"); | ||
var endTime = DateTime.Parse("2024-11-30T02:40:58.961+00:00"); | ||
var executeAffrows = fsql.Delete<Meters>() | ||
.Where(meters => meters.Ts >= startTime && meters.Ts <= endTime && meters.GroupId == 1) | ||
.ExecuteAffrows(); | ||
} | ||
|
||
[Fact] | ||
void DbFirst_GetDatabases() | ||
{ | ||
var databases = fsql.DbFirst.GetDatabases(); | ||
foreach (var database in databases) | ||
{ | ||
Console.WriteLine(database); | ||
} | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
FreeSql.Tests/FreeSql.Tests.Provider.TDengine/TDengine/Tables/Meters.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FreeSql.DataAnnotations; | ||
using FreeSql.Provider.TDengine.Attributes; | ||
|
||
namespace FreeSql.Tests.Provider.TDengine.TDengine.Tables | ||
{ | ||
[TDengineSuperTable(Name = "meters")] | ||
public class Meters | ||
{ | ||
[Column(Name = "ts")] | ||
public DateTime Ts { get; set; } | ||
|
||
[Column(Name = "current")] | ||
public float Current { get; set; } | ||
|
||
[Column(Name = "voltage")] | ||
public int Voltage { get; set; } | ||
|
||
[Column(Name = "describe", StringLength = 50)] | ||
public string? Describe { get; set; } | ||
|
||
[TDengineTag(Name = "location")] | ||
public virtual string? Location { get; set; } | ||
|
||
[TDengineTag(Name = "group_id")] | ||
public virtual int GroupId { get; set; } | ||
} | ||
|
||
[TDengineSubTable(SuperTableName = "meters", Name = "d1001")] | ||
public class D1001 : Meters | ||
{ | ||
[TDengineTag(Name = "location")] | ||
public override string Location { get; set; } = "BeiJIng.ChaoYang"; | ||
|
||
[TDengineTag(Name = "group_id")] | ||
public override int GroupId { get; set; } = 1; | ||
} | ||
|
||
[TDengineSubTable(SuperTableName = "meters", Name = "d1002")] | ||
public class D1002 : Meters | ||
{ | ||
[TDengineTag(Name = "location")] | ||
public new string Location { get; set; } = "California.SanFrancisco"; | ||
|
||
[TDengineTag(Name = "group_id")] | ||
public new int GroupId { get; set; } = 2; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
FreeSql.Tests/FreeSql.Tests.Provider.TDengine/TDengine/Tables/Users.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FreeSql.DataAnnotations; | ||
|
||
namespace FreeSql.Tests.Provider.TDengine.TDengine.Tables | ||
{ | ||
[Table(Name = "users")] | ||
public class Users | ||
{ | ||
[Column(Name = "ts")] | ||
public DateTime Ts { get; set; } | ||
|
||
[Column(Name = "id")] | ||
public float Id { get; set; } | ||
|
||
[Column(Name = "address")] | ||
public int Address { get; set; } | ||
|
||
[Column(Name = "name", StringLength = 20)] | ||
public string? Name { get; set; } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
FreeSql.Tests/FreeSql.Tests.Provider.TDengine/TDengineAdo/TDengineAdoTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace FreeSql.Tests.Provider.TDengine.TDengineAdo | ||
{ | ||
public class TDengineAdoTest | ||
{ | ||
IFreeSql fsql => g.tdengine; | ||
|
||
[Fact] | ||
public void AuditValue() | ||
{ | ||
var executeConnectTest = fsql.Ado.ExecuteConnectTest(); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace FreeSql.Tests.Provider.TDengine | ||
{ | ||
internal class g | ||
{ | ||
private static readonly Lazy<IFreeSql> tdengineLazy = new Lazy<IFreeSql>(() => | ||
{ | ||
var fsql = new FreeSql.FreeSqlBuilder() | ||
.UseConnectionString(FreeSql.DataType.TDengine, | ||
"host=localhost;port=6030;username=root;password=taosdata;protocol=Native;db=test;") | ||
.UseMonitorCommand(cmd => Console.WriteLine($"Sql:{cmd.CommandText}\r\n")) | ||
.UseNoneCommandParameter(true) | ||
.Build(); | ||
return fsql; | ||
}); | ||
|
||
public static IFreeSql tdengine => tdengineLazy.Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.