时序数据库QuestDB在Winform窗体应用

以下是QuestDB在Winform使用的代码:

//初始化

private void Init()

{

//创建数据库对象 (用法和EF Dappper一样通过new保证线程安全)

SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig()

{

ConnectionString = "host=10.3.5.227;port=8812;username=admin;password=quest;database=qdb;ServerCompatibilityMode=NoTypeLoading;",

DbType = SqlSugar.DbType.QuestDB,

IsAutoCloseConnection = true

},

db =>

{

db.Aop.OnLogExecuting = (sql, pars) =>

{

//获取原生SQL推荐 5.1.4.63 性能OK

Console.WriteLine(UtilMethods.GetNativeSql(sql, pars));

//获取无参数化SQL 对性能有影响,特别大的SQL参数多的,调试使用

//Console.WriteLine(UtilMethods.GetSqlString(DbType.SqlServer,sql,pars))

};

//注意多租户 有几个设置几个

//db.GetConnection(i).Aop

});

//建库

//建表

Db.CodeFirst.InitTables(); //所有库都支持

//插入数据

Db.Insertable(new Student() { Name = "jack", SchoolId = 1 }).ExecuteCommand();

//查询数据

Expression<Func<Student, bool>> expression = it => it.Dt < DateTime.Now && it.SchoolId == 1;

expression = expression.And(x => x.SchoolId==1);

var list = Db.Queryable().Where(expression).ToList();

MessageBox.Show(list.Count.ToString());

}

//按钮

private void button1_Click(object sender, EventArgs e)

{

Init();

}

}

//实体与数据库结构一样

public class Student

{

//数据是自增需要加上IsIdentity

//数据库是主键需要加上IsPrimaryKey

//注意:要完全和数据库一致2个属性

SugarColumn(IsPrimaryKey = true, IsIdentity = true)

public int Id { get; set; }

public int? SchoolId { get; set; }

public string Name { get; set; }

SugarColumn(IsOnlyIgnoreUpdate = true)

public DateTime Dt { get; set; }

}

//And扩展类

public static class ExpressionFuncExtender

{

private static Expression Compose(this Expression first, Expression second,

Func<Expression, Expression, Expression> merge)

{

// build parameter map (from parameters of second to parameters of first)

var map = first.Parameters.Select((f, i) => new { f, s = second.Parametersi })

.ToDictionary(p => p.s, p => p.f);

// replace parameters in the second lambda expression with parameters from the first

var secondBody = ParameterRebinder.ReplaceParameters(map, second.Body);

// apply composition of lambda expression bodies to parameters from the first expression

return Expression.Lambda(merge(first.Body, secondBody), first.Parameters);

}

///

/// Combines two given expressions by using the AND semantics.

///

/// The type of the object.

/// The first part of the expression.

/// The second part of the expression.

/// The combined expression.

public static Expression<Func<T, bool>> And(this Expression<Func<T, bool>> first,

Expression<Func<T, bool>> second)

{

return first.Compose(second, Expression.AndAlso);

}

///

/// Combines two given expressions by using the OR semantics.

///

/// The type of the object.

/// The first part of the expression.

/// The second part of the expression.

/// The combined expression.

public static Expression<Func<T, bool>> Or(this Expression<Func<T, bool>> first,

Expression<Func<T, bool>> second)

{

return first.Compose(second, Expression.OrElse);

}

}

internal class ParameterRebinder : ExpressionVisitor

{

private readonly Dictionary<ParameterExpression, ParameterExpression> _map;

internal ParameterRebinder(Dictionary<ParameterExpression, ParameterExpression> map)

{

_map = map ?? new Dictionary<ParameterExpression, ParameterExpression>();

}

internal static Expression ReplaceParameters(Dictionary<ParameterExpression, ParameterExpression> map,

Expression exp)

{

return new ParameterRebinder(map).Visit(exp);

}

protected override Expression VisitParameter(ParameterExpression p)

{

if (_map.TryGetValue(p, out var replacement))

{

p = replacement;

}

return base.VisitParameter§;

}

相关推荐
涛思数据(TDengine)18 小时前
直播预告 | 知识图谱,让文档自动变成知识网络
人工智能·ai·知识图谱·时序数据库·tdengine·工业ai
骑着蜗牛撵大象3271 天前
一套引擎撑起树表双模型:Apache IoTDB 2.0 与 TsFile 的选型答卷
apache·时序数据库·iotdb·tsfile·树模型·表模型
ZENERGY-众壹1 天前
光伏监控平台实测,三款时序数据库在 50 万测点下的真实表现
数据库·架构·运维开发·时序数据库·光伏运维
底层玩家老张3 天前
45:1压缩、19.1倍查询:1956亿行时序数据复盘
数据库·经验分享·时序数据库·存储压缩·写入优化
涛思数据(TDengine)3 天前
陶建辉获聘中国通信标准化协会本体工程专家委员会首批委员
人工智能·时序数据库·tdengine·工业互联网·工业ai
云边有个稻草人4 天前
不止于时序存储:DolphinDB 如何成为 AI 时代的工业智能底座
时序数据库·实时计算·工业物联网·流批一体·dolphindb·数据库选型·工业大数据
涛思数据(TDengine)4 天前
TDengine TSDB 3.4.3.3 上线:流计算分层闭环、虚拟表跨层引用,查询关联一次写完
数据库·人工智能·数据分析·时序数据库·tdengine·工业
byte轻骑兵4 天前
时序数据库选型指南:面向工业物联网大数据场景,Apache IoTDB落地实践
大数据·人工智能·物联网·时序数据库·人大金仓
TDengine (老段)7 天前
工业数据十大痛点系列 · 第 6 篇
数据库·时序数据库·tdengine·涛思数据·idmp·工业数据分析·ai 分析数据
骑着蜗牛撵大象3277 天前
设备监控数据存与查:Spring Boot 接入 TimescaleDB 超表的完整落地
android·spring boot·后端·springboot·时序数据库·es·设备监控