添加 SonnetDB 提供程序实现#2234
Open
maikebing wants to merge 4 commits into
Open
Conversation
实现了 SonnetDBCodeFirst,用于代码优先的数据库操作。 实现了 SonnetDBDbFirst,用于数据库优先的操作,包括表和列的元数据检索。 创建了 SonnetDBExpression,用于处理表达式到 SQL 的转换。 添加了用于 SonnetDB 格式化的全局扩展方法。 开发了 SonnetDBProvider,用于管理数据库连接和 CRUD 操作。 引入了 SonnetDBUtils,提供参数处理和 SQL 格式化相关的实用函数。 添加了 key.snk,用于为程序集赋予强名称。
There was a problem hiding this comment.
Pull request overview
该 PR 为 FreeSql 新增 SonnetDB Provider,实现 SonnetDB 的 ADO、表达式到 SQL 的转换,以及 CodeFirst/DbFirst 的基础能力,并把它接入到 FreeSqlBuilder/Ado.NET 扩展与解决方案文件中。
Changes:
- 新增
FreeSql.Provider.SonnetDB项目:Ado/Utils/Expression、CodeFirst/DbFirst、Select/Insert/Delete、以及 TAG/FIELD 属性标注。 - 将 SonnetDB 集成到
FreeSqlBuilder、AdoNetExtensions自动识别,以及DataType枚举。 - 更新
FreeSql.sln与FreeSql-lite.sln以包含新 Provider 项目,并引入强命名 key。
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| Providers/FreeSql.Provider.SonnetDB/key.snk | SonnetDB provider 强命名密钥文件 |
| Providers/FreeSql.Provider.SonnetDB/FreeSql.Provider.SonnetDB.csproj | 新 Provider 项目配置与 SonnetDB 依赖 |
| Providers/FreeSql.Provider.SonnetDB/SonnetDBProvider.cs | Provider 入口:创建各类 CRUD Provider、初始化 Ado/CodeFirst/DbFirst |
| Providers/FreeSql.Provider.SonnetDB/SonnetDBAdo/SonnetDBAdo.cs | SonnetDB ADO.NET 封装:连接池、参数转义与命令创建 |
| Providers/FreeSql.Provider.SonnetDB/SonnetDBUtils.cs | CommonUtils 适配:参数、SQL 引号、常量格式化等 |
| Providers/FreeSql.Provider.SonnetDB/SonnetDBExpression.cs | Expression → SQL 适配实现 |
| Providers/FreeSql.Provider.SonnetDB/SonnetDBCodeFirst.cs | CodeFirst:类型映射与测量表(measurement)DDL 生成 |
| Providers/FreeSql.Provider.SonnetDB/SonnetDBDbFirst.cs | DbFirst:表/列元数据检索与类型映射 |
| Providers/FreeSql.Provider.SonnetDB/SonnetDBGlobalExtensions.cs | SonnetDB 专用 FormatSonnetDB 全局扩展 |
| Providers/FreeSql.Provider.SonnetDB/Curd/SonnetDBSelect.cs | SELECT 生成(含 alias 去除与 count/limit/offset 适配) |
| Providers/FreeSql.Provider.SonnetDB/Curd/SonnetDBInsert.cs | INSERT 执行与 AOP 事件触发 |
| Providers/FreeSql.Provider.SonnetDB/Curd/SonnetDBDelete.cs | DELETE 执行(含计数补偿逻辑) |
| Providers/FreeSql.Provider.SonnetDB/Attributes/SonnetDBTagAttribute.cs | TAG 标记属性 |
| Providers/FreeSql.Provider.SonnetDB/Attributes/SonnetDBFieldAttribute.cs | FIELD 标记属性 |
| FreeSql/FreeSqlBuilder.cs | 新增 DataType.SonnetDB 的 Build 分支 |
| FreeSql/Extensions/AdoNetExtensions.cs | ADO.NET 连接类型识别新增 SndbConnection |
| FreeSql/DataType.cs | 枚举新增 SonnetDB |
| FreeSql.sln | 解决方案加入 SonnetDB provider 项目 |
| FreeSql-lite.sln | lite 解决方案加入 SonnetDB provider 项目 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+393
to
+396
| case DataType.SonnetDB: | ||
| type = Type.GetType("FreeSql.SonnetDB.SonnetDBProvider`1,FreeSql.Provider.SonnetDB")?.MakeGenericType(typeof(TMark)); | ||
| if (type == null) throwNotFind("FreeSql.Provider.SonnetDB.dll", "FreeSql.SonnetDB.SonnetDBProvider<>"); | ||
| break; |
Comment on lines
+31
to
+46
| long ret = 0; | ||
| Exception exception = null; | ||
| try | ||
| { | ||
| _orm.Ado.ExecuteNonQuery(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| exception = ex; | ||
| throw; | ||
| } | ||
| finally | ||
| { | ||
| var after = new Aop.CurdAfterEventArgs(before, exception, ret); | ||
| _orm.Aop.CurdAfterHandler?.Invoke(this, after); | ||
| } |
Comment on lines
+65
to
+80
| long ret = 0; | ||
| Exception exception = null; | ||
| try | ||
| { | ||
| await _orm.Ado.ExecuteNonQueryAsync(_connection, _transaction, CommandType.Text, sql, _commandTimeout, _params, cancellationToken); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| exception = ex; | ||
| throw; | ||
| } | ||
| finally | ||
| { | ||
| var after = new Aop.CurdAfterEventArgs(before, exception, ret); | ||
| _orm.Aop.CurdAfterHandler?.Invoke(this, after); | ||
| } |
Comment on lines
+132
to
+137
| foreach (var alias in tables.Select(a => a.Alias).Where(a => string.IsNullOrEmpty(a) == false).Distinct().OrderByDescending(a => a.Length)) | ||
| { | ||
| var escapedAlias = Regex.Escape(alias); | ||
| sql = Regex.Replace(sql, $@"\b{escapedAlias}\.", "", RegexOptions.IgnoreCase); | ||
| sql = Regex.Replace(sql, $@"(\bFROM\s+(?:""[^""]+""|\w+))\s+{escapedAlias}\b", "$1", RegexOptions.IgnoreCase); | ||
| sql = Regex.Replace(sql, $@"(\bJOIN\s+(?:""[^""]+""|\w+))\s+{escapedAlias}\b", "$1", RegexOptions.IgnoreCase); |
Comment on lines
+18
to
+25
| public override IUpdate<T1> CreateUpdateProvider<T1>(object dywhere) => | ||
| throw new NotImplementedException($"FreeSql.Provider.SonnetDB {CoreErrorStrings.S_Not_Implemented_Feature}"); | ||
|
|
||
| public override IDelete<T1> CreateDeleteProvider<T1>(object dywhere) => | ||
| new SonnetDBDelete<T1>(this, this.InternalCommonUtils, this.InternalCommonExpression, dywhere); | ||
|
|
||
| public override IInsertOrUpdate<T1> CreateInsertOrUpdateProvider<T1>() => | ||
| throw new NotImplementedException($"FreeSql.Provider.SonnetDB {CoreErrorStrings.S_Not_Implemented_Feature}"); |
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net10.0</TargetFrameworks> |
Collaborator
|
Excellent,完成之后通知一下,这边合并发布版本 |
- Implemented FormatSonnetDB extension method for safe SQL string formatting to prevent SQL injection. - Enhanced SonnetDBUtils with various utility functions for SQL parameter binding, identifier quoting, null value handling, string concatenation, and current time retrieval. - Introduced SonnetDBFunctions class containing proprietary SQL functions for FreeSql, including PID control, time series analysis, statistical aggregations, anomaly detection, and geospatial functions. - Added comprehensive documentation for each function to facilitate usage and understanding.
Author
|
已经完成。 @2881099 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.