-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
213 changed files
with
3,046 additions
and
2,659 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
3 changes: 2 additions & 1 deletion
3
src/Util.Data.Dapper.All/Infrastructure/DapperServiceRegistrar.cs
This file contains 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
2 changes: 1 addition & 1 deletion
2
src/Util.Data.Dapper.All/Infrastructure/ServiceRegistrarConfigExtensions.cs
This file contains 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
This file contains 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
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
src/Util.Data.Dapper.Core/Infrastructure/DapperServiceRegistrar.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Dapper; | ||
using System; | ||
using Util.Data.Dapper.TypeHandlers; | ||
using Util.Infrastructure; | ||
|
||
namespace Util.Data.Dapper.Infrastructure; | ||
|
||
/// <summary> | ||
/// Dapper服务注册器 | ||
/// </summary> | ||
public class DapperServiceRegistrar : IServiceRegistrar { | ||
/// <summary> | ||
/// 获取服务名 | ||
/// </summary> | ||
public static string ServiceName => "Util.Data.Dapper.Infrastructure.DapperServiceRegistrar"; | ||
|
||
/// <summary> | ||
/// 排序号 | ||
/// </summary> | ||
public int OrderId => 810; | ||
|
||
/// <summary> | ||
/// 是否启用 | ||
/// </summary> | ||
public bool Enabled => ServiceRegistrarConfig.IsEnabled( ServiceName ); | ||
|
||
/// <summary> | ||
/// 注册服务 | ||
/// </summary> | ||
/// <param name="serviceContext">服务上下文</param> | ||
public Action Register( ServiceContext serviceContext ) { | ||
SqlMapper.AddTypeHandler( new ExtraPropertiesTypeHandler() ); | ||
return null; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Util.Data.Dapper.Core/Infrastructure/ServiceRegistrarConfigExtensions.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Util.Infrastructure; | ||
|
||
namespace Util.Data.Dapper.Infrastructure; | ||
|
||
/// <summary> | ||
/// Dapper服务注册器配置扩展 | ||
/// </summary> | ||
public static class ServiceRegistrarConfigExtensions { | ||
/// <summary> | ||
/// 启用Dapper服务注册器 | ||
/// </summary> | ||
/// <param name="config">服务注册器配置</param> | ||
public static ServiceRegistrarConfig EnableDapperServiceRegistrar( this ServiceRegistrarConfig config ) { | ||
ServiceRegistrarConfig.Enable( DapperServiceRegistrar.ServiceName ); | ||
return config; | ||
} | ||
|
||
/// <summary> | ||
///禁用Dapper服务注册器 | ||
/// </summary> | ||
/// <param name="config">服务注册器配置</param> | ||
public static ServiceRegistrarConfig DisableDapperServiceRegistrar( this ServiceRegistrarConfig config ) { | ||
ServiceRegistrarConfig.Disable( DapperServiceRegistrar.ServiceName ); | ||
return config; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/Util.Data.Dapper.Core/Properties/UtilDataDapperResource.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
61 changes: 61 additions & 0 deletions
61
src/Util.Data.Dapper.Core/TypeHandlers/ExtraPropertiesTypeHandler.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Data; | ||
using System.Text.Encodings.Web; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Text.Unicode; | ||
using Dapper; | ||
using Util.Domain.Extending; | ||
using Util.SystemTextJson; | ||
|
||
namespace Util.Data.Dapper.TypeHandlers; | ||
|
||
/// <summary> | ||
/// 扩展属性类型转换器 | ||
/// </summary> | ||
public class ExtraPropertiesTypeHandler : SqlMapper.TypeHandler<ExtraPropertyDictionary> { | ||
/// <summary> | ||
/// 设置值 | ||
/// </summary> | ||
/// <param name="parameter">参数</param> | ||
/// <param name="value">扩展属性值</param> | ||
public override void SetValue( IDbDataParameter parameter, ExtraPropertyDictionary value ) { | ||
if ( parameter == null ) | ||
return; | ||
if ( value == null ) | ||
return; | ||
parameter.Value = PropertiesToJson( value ); | ||
} | ||
|
||
/// <summary> | ||
/// 扩展属性转换为json | ||
/// </summary> | ||
private static string PropertiesToJson( ExtraPropertyDictionary extraProperties ) { | ||
var options = new JsonSerializerOptions { | ||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, | ||
Encoder = JavaScriptEncoder.Create( UnicodeRanges.All ), | ||
Converters = { | ||
new UtcDateTimeJsonConverter(), | ||
new UtcNullableDateTimeJsonConverter() | ||
} | ||
}; | ||
return Util.Helpers.Json.ToJson( extraProperties, options ); | ||
} | ||
|
||
/// <summary> | ||
/// 转换值 | ||
/// </summary> | ||
/// <param name="value">json字符串</param> | ||
public override ExtraPropertyDictionary Parse( object value ) { | ||
return JsonToProperties( value.SafeString() ); | ||
} | ||
|
||
/// <summary> | ||
/// json转换为扩展属性 | ||
/// </summary> | ||
private static ExtraPropertyDictionary JsonToProperties( string json ) { | ||
if ( json.IsEmpty() || json == "{}" ) | ||
return new ExtraPropertyDictionary(); | ||
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; | ||
return Util.Helpers.Json.ToObject<ExtraPropertyDictionary>( json, options ) ?? new ExtraPropertyDictionary(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
4 changes: 3 additions & 1 deletion
4
src/Util.Data.Dapper.MySql/Sql/Builders/MySqlExistsSqlBuilder.cs
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
using MySqlConnector; | ||
|
||
namespace Util.Data.Sql; | ||
namespace Util.Data.Dapper.Sql; | ||
|
||
/// <summary> | ||
/// MySql数据库工厂 | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.