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

embedded/2025/3/26 9:55:46/

以下是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.ppmy.cn/embedded/176251.html

相关文章

HTTP/HTTPS 中 GET 请求和 POST 请求的区别与联系

一、基础概念 HTTP (HyperText Transfer Protocol, 超文本传输协议) 是一种用于浏览器与服务器之间进行数据交互的协议。HTTPS (加密的 HTTP) 则通过 SSL/TLS 协议实现通信加密与数据安全性。 二、GET 和 POST 概述 GET 请求: 用于从服务器获取资源。 POST 请求: 用于将数据…

用selenium+ChromeDriver豆瓣电影 肖申克的救赎 短评爬取(pycharm 爬虫)

一、豆瓣电影 肖申克的救赎 短评url=https://movie.douban.com/subject/1292052/comments 二、基本知识点讲解 1. Selenium 的基本使用 Selenium 是一个用于自动化浏览器操作的库,常用于网页测试和爬虫。代码中使用了以下 Selenium 的核心功能: webdriver.Chrome: 启动 Chr…

大模型在非小细胞肺癌预测及治疗方案制定中的应用研究报告

目录 一、引言 1.1 研究背景与意义 1.2 研究目的与创新点 二、大模型预测非小细胞肺癌的原理与方法 2.1 相关大模型介绍 2.2 数据收集与预处理 2.3 特征工程 2.4 模型训练与优化 三、术前风险预测与手术方案制定 3.1 术前风险预测指标 3.2 大模型预测术前风险的效果…

DeepSeek写打台球手机小游戏

DeepSeek写打台球手机小游戏 提问 根据提的要求&#xff0c;让DeepSeek整理的需求&#xff0c;进行提问&#xff0c;内容如下&#xff1a; 请生成一个包含以下功能的可运行移动端打台球小游戏H5文件&#xff1a; 要求 可以重新开始游戏 可以暂停游戏 有白球和其他颜色的球&am…

机器人的手眼标定——机器人抓取系统基础系列(五)

机器人的手眼标定——机器人抓取系统基础系列&#xff08;五&#xff09; 前言一、机器人标定相关概念1.1 内参标定和外参标定1.2 Eye-in-Hand 和 Eye-to-Hand1.3 ArUco二维码和棋盘格标定区别 二、机器人标定基本原理2.1 机器人抓取系统坐标系2.2 标定原理 三、标定步骤和注意…

课外活动:怎么理解可变成本?

可变成本深度解析 &#x1f9ee; 一、可变成本的本质 #mermaid-svg-qoqQaFxQBuZZfAD2 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-qoqQaFxQBuZZfAD2 .error-icon{fill:#552222;}#mermaid-svg-qoqQaFxQBuZZfAD2 …

自然语言处理(5)—— 中文分词

中文分词的基本原理及实现 1. 什么是词2. 基本原理3. 发展趋势&#xff1a;多数场景无需显式分词 信息处理的目标是使用计算机能够理解和产生自然语言。而自然语言理解和产生的前提是对语言能够做出全面的解析。 汉语词汇是语言中能够独立运用的最小的语言单位&#xff0c;是语…

OpenSSL 3.0.2 报 dh key too small 的问题

问题复现 运行命令 curl 访问一个 https 网站&#xff0c;可能会出现 "dh key too small" 的问题。 > curl -v --insecure https://some_web_site * Trying 175.21.4.7:443... * Connected to some_web_site (175.21.4.7) port 443 (#0) * ALPN: offers h2,…