-
Notifications
You must be signed in to change notification settings - Fork 48
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
85 changed files
with
9,733 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<#@ template debug="false" hostspecific="false" language="C#" #> | ||
<#@ assembly name="System.Core" #> | ||
<#@ assembly name="System.Data" #> | ||
<#@ assembly name="$(SolutionDir)\YC51.References\Dapper.dll" #> | ||
<#@ assembly name="$(SolutionDir)\YC51.References\MySql.Data.dll" #> | ||
<#@ import namespace="System.Linq" #> | ||
<#@ import namespace="System.Text" #> | ||
<#@ import namespace="System.Collections.Generic" #> | ||
<#@ import namespace="System.Data" #> | ||
<#@ import namespace="MySql.Data.MySqlClient" #> | ||
<#@ import namespace="Dapper" #> | ||
<#@ output extension=".cs" #> | ||
<# | ||
//数据库连接字符串 | ||
var connectionString = "server=127.0.0.1;user id=root;password=1024;database=test;"; | ||
#> | ||
<# | ||
var connection = new MySqlConnection(connectionString); | ||
var tablesql = string.Format("SELECT TABLE_NAME as TableName,TABLE_TYPE as TableType,TABLE_COMMENT as TableComment from INFORmation_schema.TABLES WHERE TABLE_SCHEMA='{0}'", connection.Database); | ||
var columnsql = string.Format("SELECT TABLE_NAME as TableName,COLUMN_NAME as ColumnName,COLUMN_COMMENT as ColumnComment,COLUMN_DEFAULT as ColumnDefault,IS_NULLABLE as IsNullable,DATA_TYPE as DataType,COLUMN_TYPE as ColumnType,COLUMN_KEY as ColumnKey,EXTRA as Extra FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='{0}' ORDER BY ORDINAL_POSITION", connection.Database); | ||
var tables = connection.Query<Table>(tablesql).ToList(); | ||
var columns = connection.Query<Column>(columnsql).ToList(); | ||
connection.Close(); | ||
#> | ||
using System; | ||
using YC51.SqlBatis.Attributes; | ||
|
||
namespace YC51.MiniProgram.Service | ||
{ | ||
<#foreach(var table in tables){#> | ||
|
||
/// <summary> | ||
/// <#=table.TableComment#> | ||
/// 更新时间:<#=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")#> | ||
/// </summary> | ||
[Table("<#=table.TableName#>")] | ||
public partial class <#=Utils.Pascal(table.TableName)#> | ||
{ | ||
<#foreach(var column in columns.FindAll(f => f.TableName == table.TableName)){#> | ||
/// <summary> | ||
/// <#=column.ColumnComment#> | ||
/// </summary> | ||
[Column("<#= column.ColumnName #>")] | ||
<#=column.ColumnKey == "PRI"?"[PrimaryKey]\r\n":""#><#=column.Extra == "auto_increment"?"[Identity]\r\n":"" #><#=column.ColumnDefault != null?"[Default]\r\n":"" #> | ||
public <#= Utils.GetCSharpType(column.DataType) #> <#= Utils.Pascal(column.ColumnName) #> { get; set; } | ||
<#}#>} | ||
<#}#> | ||
} | ||
|
||
|
||
|
||
<#+ | ||
public class Table | ||
{ | ||
public string TableName { get; set; } | ||
public string TableType { get; set; } | ||
public string TableComment { get; set; } | ||
} | ||
public class Column | ||
{ | ||
public string TableName { get; set; } | ||
public string ColumnName { get; set; } | ||
public string ColumnComment { get; set; } | ||
public string ColumnDefault { get; set; } | ||
public string IsNullable { get; set; } | ||
public string ColumnType { get; set; } | ||
public string DataType { get; set; } | ||
public string ColumnKey { get; set; } | ||
public string Extra { get; set; } | ||
} | ||
public static class Utils | ||
{ | ||
//字段类型映射 | ||
public static string GetCSharpType(string columnType) | ||
{ | ||
var type = "object"; | ||
switch (columnType) | ||
{ | ||
case "varchar": type = "string"; break; | ||
case "text": type = "string"; break; | ||
case "char": type = "string"; break; | ||
case "bit": type = "bool?"; break; | ||
case "tinyint": type = "int?"; break; | ||
case "smallint": type = "int?"; break; | ||
case "int": type = "int?"; break; | ||
case "integer": type = "int?"; break; | ||
case "bigint": type = "int?"; break; | ||
case "mediumint": type = "int?"; break; | ||
case "real": type = "float?"; break; | ||
case "float": type = "float?"; break; | ||
case "double": type = "double?"; break; | ||
case "decimal": type = "decimal?"; break; | ||
case "date": type = "DateTime?"; break; | ||
case "datetime": type = "DateTime?"; break; | ||
case "json": type = "System.Text.Json.JsonElement?"; break; | ||
} | ||
return type; | ||
} | ||
//Pacsl命名转换 | ||
public static string Pascal(string name) | ||
{ | ||
var list = new List<string>(); | ||
foreach (var item in name.Split('_')) | ||
{ | ||
list.Add(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(item.ToLower())); | ||
} | ||
return string.Join("",list); | ||
} | ||
//Camel命名转换 | ||
public static string Camel(string name) | ||
{ | ||
name = Pascal(name); | ||
return char.ToLower(name[0]) + name.Substring(1); | ||
} | ||
} | ||
#> |
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,21 @@ | ||
using System; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 字段映射 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public class ColumnAttribute : Attribute | ||
{ | ||
internal string Name { get; set; } | ||
/// <summary> | ||
/// 属性字段映射 | ||
/// </summary> | ||
/// <param name="name">数据库字段名</param> | ||
public ColumnAttribute(string name = null) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
} |
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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 计算列,如果字段一个是计算列则新增和修改的时候不会处理 | ||
/// </summary> | ||
public class ComplexTypeAttribute : Attribute | ||
{ | ||
|
||
} | ||
} |
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,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 并发检查,如果字段属性是number类型则用时间戳,否则使用GUID | ||
/// </summary> | ||
public class ConcurrencyCheckAttribute : Attribute | ||
{ | ||
|
||
} | ||
} |
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,13 @@ | ||
using System; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 默认值约束 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public class DefaultAttribute : Attribute | ||
{ | ||
|
||
} | ||
} |
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,13 @@ | ||
using System; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 数据库函数标识 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class FunctionAttribute : Attribute | ||
{ | ||
|
||
} | ||
} |
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,13 @@ | ||
using System; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 自增列标识 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public class IdentityAttribute : Attribute | ||
{ | ||
|
||
} | ||
} |
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,13 @@ | ||
using System; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 忽略映射 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public class NotMappedAttribute: Attribute | ||
{ | ||
|
||
} | ||
} |
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,13 @@ | ||
using System; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 主键约束 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public class PrimaryKeyAttribute : Attribute | ||
{ | ||
|
||
} | ||
} |
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,17 @@ | ||
using System; | ||
|
||
namespace Dapper.Attributes | ||
{ | ||
/// <summary> | ||
/// 表名映射 | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class TableAttribute : Attribute | ||
{ | ||
internal string Name { get; set; } | ||
public TableAttribute(string name = null) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
} |
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,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks> | ||
<NoWarn>$(NoWarn);1591</NoWarn> | ||
<Authors>chaeyeon</Authors> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<Description>A high performance Micro-ORM supporting SQL Server, MySQL, Sqlite, etc..</Description> | ||
<PackageProjectUrl>https://github.com/1448376744/Dapper.Linq</PackageProjectUrl> | ||
<RepositoryUrl>https://github.com/1448376744/Dapper.Linq</RepositoryUrl> | ||
<RepositoryType>GIT</RepositoryType> | ||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Copyright>chaeyeon</Copyright> | ||
<Company>chaeyeon</Company> | ||
<PackageId>Dapper.Common</PackageId> | ||
<Version>3.0.0</Version> | ||
<AssemblyVersion>3.0.0</AssemblyVersion> | ||
<FileVersion>3.0.0</FileVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"> | ||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> | ||
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" /> | ||
<PackageReference Include="System.Xml.XDocument" Version="4.3.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'net45'"> | ||
<PackageReference Include="System.ValueTuple" Version="4.5.0" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.