• Stars
    star
    171
  • Rank 222,266 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

EntityFramework, EF Core, ADO.NET, ORM,Stmt,TDengine

IoTSharp.EntityFrameworkCore.Taos

项目简介

ADO.Net Entity, Framework, EF, Core, Data, O/RM, entity-framework-core,TDengine

IoTSharp.Data.Taos 是 TDengine的ADO.Net提供程序。 它将允许你通过原生动态库、WebSocket、RESTful 三种协议访问TDengine,通过 Schemaless 完美实现了ExecuteBulkInsert批量插入、Stmt 实现了参数化执行。

连接协议说明

协议 使用 依赖 说明
WebSocket builder.UseWebSocket() 无依赖 纯C#实现, 支持 Schemaless 和 Stmt参数化
Cloud DSN builder_cloud.UseCloud_DSN() 无依赖 纯C#实现, 支持 Schemaless 和 Stmt参数化
Native builder.UseNative() libtaos 原生协议, 支持3.0.x libtaos 动态库,支持 Schemaless 和 Stmt参数化。使用前必须安装 TDengine-client
RESTful builder.UseRESTful() 无依赖 纯C#实现, 不支持 Schemaless 和 Stmt参数化

连接字符串示例

连接方式 示例
TDengine云服务 Data Source=gw.us-east.azure.cloud.tdengine.com;DataBase=iotsharp;Username=root;Password=taosdata;Port=80;PoolSize=20;Protocol=WebSocket;Token=4592d868d1b57c812edb3d8c11b4bbd1ffc747c0
使用原生库libtaos Data Source=DEVPER;DataBase=db_20230301123636;Username=root;Password=taosdata;Port=6030;PoolSize=20;Protocol=Native
使用 Http RESTful Data Source=DEVPER;DataBase=db_20230301123636;Username=root;Password=taosdata;Port=6041;PoolSize=20;Protocol=RESTful
使用 WebSocket Data Source=DEVPER;DataBase=db_20230301123636;Username=root;Password=taosdata;Port=6041;PoolSize=20;Protocol=WebSocket

Schemaless

通过 Schemaless 实现的 ExecuteBulkInsert 支持 TSDB_SML_LINE_PROTOCOL 和TSDB_SML_JSON_PROTOCOL 。 透过TSDB_SML_JSON_PROTOCOL也支持了InfluxDB Client中的 RecordData 的数据写法。

RecordData示例

  var rec=  RecordData.table("meters").Tag("location", "Beijing.Haidian").Tag("groupid", "2").Timestamp(DateTime.Now.ToUniversalTime(), TimePrecision.Ms)
                .Field("current", 12.1).Field("voltage", 234.0).Field("phase",0.33);
            int result = connection.ExecuteBulkInsert(rec);

IoTSharp.EntityFrameworkCore.Taos 是一个Entity Framework Core 的提供器, 基于IoTSharp.Data.Taos实现。 (原名称为 Maikebing.EntityFrameworkCore.Taos)


Build status License

NuGet名称 版本 下载量 说明
IoTSharp.Data.Taos IoTSharp.Data.Taos Nuget ADO.Net Core 基础组件
IoTSharp.EntityFrameworkCore.Taos IoTSharp.EntityFrameworkCore.Taos Nuget 供EF Core使用的组件
IoTSharp.HealthChecks.Taos IoTSharp.HealthChecks.Taos Nuget 供Asp.Net Core 使用的健康检查组件

TDengine技术开放日 — 从技术创新和设计思想,认识TDengine

荣誉证书

如何使用?

Example

基本示例:

    ///Specify the name of the database
    string database = "db_" + DateTime.Now.ToString("yyyyMMddHHmmss");
      string database = "db_" + DateTime.Now.ToString("yyyyMMddHHmmss");
      var builder = new TaosConnectionStringBuilder()
      {
            DataSource = "127.0.0.1",
            DataBase = database,
            Username = "root",
            Password = "kissme",
            Port=6060
            };
    //Example for ADO.Net 
    using (var connection = new TaosConnection(builder.ConnectionString))
    {
        connection.Open();
        Console.WriteLine("create {0} {1}", database, connection.CreateCommand($"create database {database};").ExecuteNonQuery());
        Console.WriteLine("create table t {0} {1}", database, connection.CreateCommand($"create table {database}.t (ts timestamp, cdata int);").ExecuteNonQuery());
        Console.WriteLine("insert into t values  {0}  ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ms")}', 10);").ExecuteNonQuery());
        Console.WriteLine("insert into t values  {0} ", connection.CreateCommand($"insert into {database}.t values ('{DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss.ms")}', 20);").ExecuteNonQuery());
        var cmd_select = connection.CreateCommand();
        cmd_select.CommandText = $"select * from {database}.t";
        var reader = cmd_select.ExecuteReader();
        Console.WriteLine(cmd_select.CommandText);
        Console.WriteLine("");
        ConsoleTableBuilder.From(reader.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine();
        Console.WriteLine("");
        Console.WriteLine("DROP TABLE  {0} {1}", database, connection.CreateCommand($"DROP TABLE  {database}.t;").ExecuteNonQuery());
        Console.WriteLine("DROP DATABASE {0} {1}", database, connection.CreateCommand($"DROP DATABASE   {database};").ExecuteNonQuery());
        connection.Close();
    }
    //Example for  Entity Framework Core  
    using (var context = new TaosContext(new DbContextOptionsBuilder()
                                            .UseTaos(builder.ConnectionString).Options))
    {
        Console.WriteLine("EnsureCreated");
        context.Database.EnsureCreated();
        for (int i = 0; i < 10; i++)
        {
            var rd = new Random();
            context.sensor.Add(new sensor() { ts = DateTime.Now.AddMilliseconds(i), degree = rd.NextDouble(), pm25 = rd.Next(0, 1000) });
        }
        Console.WriteLine("Saving");
        context.SaveChanges();
        Console.WriteLine("");
        Console.WriteLine("from s in context.sensor where s.pm25 > 0 select s ");
        Console.WriteLine("");
        var f = from s in context.sensor where s.pm25 > 0 select s;
        var ary = f.ToArray();
        ConsoleTableBuilder.From(ary.ToList()).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine();
        context.Database.EnsureDeleted();
    }
    Console.WriteLine("");
    Console.WriteLine("Pass any key to exit....");
    Console.ReadKey();

用于物联网的超级表示例:

IoTSharp/Storage/TaosStorage.cs

   using (var connection = new TaosConnection(builder.ConnectionString))
            {
                connection.Open();
                Console.WriteLine("ServerVersion:{0}", connection.ServerVersion);
                connection.CreateCommand("DROP DATABASE IF EXISTS  IoTSharp").ExecuteNonQuery();
                connection.CreateCommand("CREATE DATABASE IoTSharp KEEP 365 DAYS 10 BLOCKS 4;").ExecuteNonQuery();
                connection.ChangeDatabase("IoTSharp");
                connection.CreateCommand("CREATE TABLE IF NOT EXISTS telemetrydata  (ts timestamp,value_type  tinyint, value_boolean bool, value_string binary(10240), value_long bigint,value_datetime timestamp,value_double double)   TAGS (deviceid binary(32),keyname binary(64));").ExecuteNonQuery();
                //connection.CreateCommand($"CREATE TABLE dev_Thermometer USING telemetrydata TAGS (\"Temperature\")").ExecuteNonQuery();
                var devid = $"{Guid.NewGuid():N}";
                UploadTelemetryData(connection, devid, "Temperature", 999);
                UploadTelemetryData(connection,devid,   "Humidity", 888);
                var devid2 = $"{Guid.NewGuid():N}";
                UploadTelemetryData(connection, devid2, "Temperature", 777);
                UploadTelemetryData(connection, devid2, "Humidity", 666);
                var reader2 = connection.CreateCommand("select last_row(*) from telemetrydata group by deviceid,keyname ;").ExecuteReader();
                ConsoleTableBuilder.From(reader2.ToDataTable()).WithFormat(ConsoleTableBuilderFormat.Default).ExportAndWriteLine();
                connection.Close();
            }
            
             static void UploadTelemetryData(  TaosConnection connection, string devid, string keyname, int count)
        {
            for (int i = 0; i < count; i++)
            {
                connection.CreateCommand($"INSERT INTO device_{devid}_{keyname} USING telemetrydata TAGS(\"{devid}\",\"{keyname}\")  (ts,value_type,value_long) values (now,2,{i});").ExecuteNonQuery();
            }
        }
        

More Repositories

1

TDengine

High-performance, scalable time-series database designed for Industrial IoT (IIoT) scenarios
C
23,274
star
2

driver-go

taos go driver
Go
88
star
3

grafanaplugin

TDengine datasource plugin for grafana
TypeScript
61
star
4

taosadapter

Taos Adapter for TDengine
Go
56
star
5

TDengine-Operator

Setup TDengine on Kubenetes https://taosdata.github.io/TDengine-Operator
Shell
55
star
6

awesome-tdengine

🎉 A curated list of awesome projects related to TDengine
53
star
7

taos-connector-python

TDengine connector for Python
Python
46
star
8

taos-connector-jdbc

Connecting Java Application With a TDengine Database.
Java
41
star
9

taos-connector-rust

TDengine connector for Rust
Rust
30
star
10

Bailongma

An data transporter for tdengine
Go
24
star
11

taos-tools

taos-tools are some useful tool collections for TDengine.
C
24
star
12

taos-connector-dotnet

TDegnine connector for .Net
C#
22
star
13

libtaos-rs

Rust
20
star
14

blm3

Go
17
star
15

kafka-connect-tdengine

Java
15
star
16

bailongma-rs

TDengine adapters for prometheus
Rust
13
star
17

timeseriesdatabase-comparisons

Shell
12
star
18

taos-connector-node

TDengine connector for Node.js.
JavaScript
12
star
19

taos_odbc

odbc connector for tdengine
C
10
star
20

go-demo-kafka

TDengine Demo Series - Consume Messages from Kafka
Go
9
star
21

tdengine_gorm

Go
9
star
22

vscode-tdengine

visual studio code extension for TDengine
JavaScript
9
star
23

official_website

This is the repository including all source codes of https://www.taosdata.com/.
JavaScript
7
star
24

taoskeeper

Go
6
star
25

go-utils

Go
5
star
26

TSZ

Error-bounded Lossy Data Compressor For Float Double
C
5
star
27

taosws-rs

Rust
4
star
28

homebrew-tdengine

Ruby
4
star
29

tsbs

Time Series Benchmark Suite forked from TimeScale
Go
3
star
30

gds-connector

TDengine connector for Google Data Studio
JavaScript
3
star
31

tdengine-modeling-and-querying-101

101 Examples of TDengine Modeling and Querying.
2
star
32

eii-tdengine-connector

Go
2
star
33

tdengine-playground

Playground of TDengine
Vue
2
star
34

.github

TAOS Data Public Organization Profile
2
star
35

subscribeDemo-java

Java
2
star
36

flink-connector-tdengine

flink connector tdengin
Java
1
star