当前位置: 首页 > news >正文

时序数据库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.Parameters[i] })
.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§;
}

相关文章:

  • 记录一次truncate导致MySQL夯住的故障
  • 【DETR】训练自己的数据集以及YOLO数据集格式(txt)转化成COCO格式(json)
  • 计算机视觉总结
  • Golang开发棋牌游戏中的坑
  • fastapi下载图片
  • 嵌入式八股RTOS与Linux--hea4与TLSF篇
  • 《基于深度学习的指纹识别智能门禁系统》开题报告
  • Spring IOC核心详解:掌握控制反转与依赖注入
  • (四)---四元数的基础知识-(定义)-(乘法)-(逆)-(退化到二维复平面)-(四元数乘法的导数)
  • 【Spring IoC DI】深入解析 IoC & DI :Spring框架的核心设计思想和 IoC 与 DI 的思想和解耦优势
  • IDEA 快捷键ctrl+shift+f 无法全局搜索内容的问题及解决办法
  • MySQL表的增加、查询、修改、删除的基础操作
  • BEVFormer报错(预测场景与真值场景的sample_token不匹配)
  • springCloud集成tdengine(原生和mapper方式) 其一
  • Springboot之RequestAttributes学习笔记
  • 使用selenium来获取数据集
  • 在Ubuntu 22.04 中安装Docker的详细指南
  • elasticsearch 通用笔记
  • windows 安装 Elasticsearch
  • 六、GPIO中断控制器(1)—— pcf8575
  • 龙湖集团:今年前4个月销售220.8亿元,4月新增两块土地储备
  • 春秋航空:如果供应链持续改善、油价回落到合理水平,公司补充运力的需求将会增长
  • 三星“七天机”质保期内屏幕漏液被要求自费维修,商家:系人为损坏
  • 习近平向中国人民解放军仪仗队致意
  • 暴雨及强对流天气黄色预警已发布!南方进入本轮降雨最强时段
  • 湖北奥莱斯轮胎公司逃避监管排放大气污染物被罚25万元