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

时序数据库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§;
}


http://www.kler.cn/a/598306.html

相关文章:

  • XSS 攻击向量与绕过技巧
  • 银河麒麟桌面版包管理器(三)
  • conda 常用命令
  • datetime“陷阱”与救赎:扒“时间差值”证道
  • 【计算机网络】网络编程
  • Perl语言的计算机视觉
  • 可视化动态表单动态表单界的天花板--Formily(阿里开源)
  • 基于django美团美食销售数据分析与可视化系统设计与实现(源码+lw+部署文档+讲解),源码可白嫖!
  • 测试用例设计方法与Prompt转化:一键生成高效提示词的实用指南
  • 题型笔记 | Apriori算法
  • 从零构建大语言模型全栈开发指南:第二部分:模型架构设计与实现-2.1.2多头注意力扩展与掩码机制(因果掩码与填充掩码)
  • 阿里云搭建docker私有仓库
  • [RoarCTF 2019]Easy Calc-3.23BUUCTF练习day5(2)
  • WPF控件DataGrid介绍
  • STM32HAL库,解决串口UART中断接收到的第一个字节数据丢失
  • 解密模型上下文协议(MCP):下一代AI交互框架
  • Redis为什么用跳表实现有序集合?
  • HTML 表单处理进阶:验证与提交机制的学习心得与进度(二)
  • datawhale组队学习-大语言模型-task5:主流模型架构及新型架构
  • 2025前端面试题记录