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

}

相关推荐
一只大侠的侠18 小时前
工业物联网数据困局:DolphinDB 如何打通“数据—计算—AI—决策“全链路
时序数据库
辰辉创聚19 小时前
重组蛋白聚集的形成机制及其对蛋白活性的影响
opencv·时序数据库·visual studio·重组蛋白·蛋白聚集·蛋白活性·蛋白聚集体
大帅点兵20 小时前
车载设备采集数据用十六进制完整原因(车载 CAN / 车规设备专用)
时序数据库·嵌入式实时数据库
TDengine (老段)1 天前
TDengine 常见问题 TOP3
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
DolphinDB2 天前
存算一体、云边协同:DolphinDB 为石油化工行业设备监测打造高效数据底座
物联网·时序数据库·dolphindb
KaiwuDB2 天前
阿里云 InfluxDB® 版退市倒计时 | KaiwuDB 提供专属迁移支持
时序数据库·influxdb·kaiwudb·数据迁移·浪潮 kaiwudb 数据库
TDengine (老段)3 天前
TDengine 常见问题 TOP4
数据库·物联网·时序数据库·tdengine·涛思数据·升级·tdengine 问题
金融小师妹3 天前
事件驱动分析:美联储决议临近,黄金弱势运行的AI政策定价框架
大数据·eclipse·时序数据库
DolphinDB4 天前
持续升级!DolphinDB 全面完成银河麒麟 V11 兼容性认证
时序数据库·信创·银河麒麟·dolphindb
天天喝旺仔4 天前
Prometheus + Grafana 监控告警体系搭建实战:从 Exporter 指标采集、PromQL 查询到 Alertmanager 告警落地
容器·kubernetes·grafana·prometheus·时序数据库