Skip to content

Commit

Permalink
add support global default TableFilter -> fix #32
Browse files Browse the repository at this point in the history
``` yml
TableFilter:
  IgnoreNoPKTable: true
  IgnoreView: true
```
  • Loading branch information
Ahoo-Wang committed Jun 4, 2019
1 parent 787184f commit 24ea67c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor>2</VersionMajor>
<VersionMinor>2</VersionMinor>
<VersionPatch>50</VersionPatch>
<VersionPatch>52</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
</PropertyGroup>
</Project>
16 changes: 7 additions & 9 deletions doc/SmartCode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Output:
Type: File
Path: 'E:\SmartSql-Starter'
Parameters:
SmartSqlVersion: '4.0.56'
SmartSqlVersion: '4.0.58'
SmartSqlSchemaVersion: '4.0.42'
BuildDir: 'E:\SmartSql-Starter\build'
DockerImage: 'smartsql.starter'
Expand Down Expand Up @@ -44,6 +44,10 @@ NamingConverter:
Delimiter: '_'
Converter:
Type: Pascal

TableFilter:
IgnoreNoPKTable: true
IgnoreView: true

# 构建任务
Build:
Expand Down Expand Up @@ -101,6 +105,8 @@ Build:
Module: Entity
TemplateEngine:
Path: Entity.cshtml
IgnoreNoPKTable: false
IgnoreView: false
Output:
Path: 'src/{{Project.Module}}.{{Build.Module}}'
Name: '{{Items.CurrentTable.ConvertedName}}'
Expand All @@ -111,8 +117,6 @@ Build:
Module: Repository
TemplateEngine:
Path: Repository.cshtml
IgnoreNoPKTable: true
IgnoreView: true
Output:
Path: 'src/{{Project.Module}}.{{Build.Module}}'
Name: 'I{{Items.CurrentTable.ConvertedName}}Repository'
Expand All @@ -123,8 +127,6 @@ Build:
Module: Service
TemplateEngine:
Path: Service.cshtml
IgnoreNoPKTable: true
IgnoreView: true
Output:
Path: 'src/{{Project.Module}}.{{Build.Module}}'
Name: '{{Items.CurrentTable.ConvertedName}}Service'
Expand All @@ -135,8 +137,6 @@ Build:
Module: API
TemplateEngine:
Path: API/APIController.cshtml
IgnoreNoPKTable: true
IgnoreView: true
Output:
Path: 'src/{{Project.Module}}.{{Build.Module}}/Controllers'
Name: '{{Items.CurrentTable.ConvertedName}}Controller'
Expand All @@ -150,8 +150,6 @@ Build:
Path: 'src/{{Project.Module}}.Repository/Maps'
Name: '{{Items.CurrentTable.ConvertedName}}'
Extension: .xml
IgnoreNoPKTable: true
IgnoreView: true

# Please install dotnet-format first!
# dotnet tool install -g dotnet-format
Expand Down
16 changes: 11 additions & 5 deletions src/SmartCode.Generator/BuildTasks/AbstractDbBuildTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,32 @@ protected IList<Table> FilterTable(IEnumerable<Table> tables, string buildKey, B
{
_logger.LogInformation($"FilterTable Build:{buildKey} Start!");
IEnumerable<Table> buildTables = CopyTables(tables);
if (build.IgnoreNoPKTable)
if (build.IgnoreNoPKTable.HasValue && build.IgnoreNoPKTable.Value)
{
_logger.LogInformation($"FilterTable Build:{buildKey} IgnoreNoPKTable!");
buildTables = buildTables.Where(m => m.PKColumn != null);
}
if (build.IgnoreView)

if (build.IgnoreView.HasValue && build.IgnoreView.Value)
{
_logger.LogInformation($"FilterTable Build:{buildKey} IgnoreView!");
buildTables = buildTables.Where(m => m.Type != Table.TableType.View);
}

if (build.IgnoreTables != null)
{
_logger.LogInformation($"FilterTable Build:{buildKey} IgnoreTables: [{String.Join(",", build.IgnoreTables)}]!");
_logger.LogInformation(
$"FilterTable Build:{buildKey} IgnoreTables: [{String.Join(",", build.IgnoreTables)}]!");
buildTables = buildTables.Where(m => !build.IgnoreTables.Contains(m.Name));
}

if (build.IncludeTables != null)
{
_logger.LogInformation($"FilterTable Build:{buildKey} IncludeTables: [{String.Join(",", build.IncludeTables)}]!");
_logger.LogInformation(
$"FilterTable Build:{buildKey} IncludeTables: [{String.Join(",", build.IncludeTables)}]!");
buildTables = buildTables.Where(m => build.IncludeTables.Contains(m.Name));
}

_logger.LogInformation($"FilterTable Build:{buildKey} End!");
return buildTables.ToList();
}
Expand Down Expand Up @@ -83,4 +89,4 @@ protected IList<Table> CopyTables(IEnumerable<Table> tables)
}).ToList();
}
}
}
}
5 changes: 3 additions & 2 deletions src/SmartCode/Configuration/Build.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace SmartCode.Configuration
Expand All @@ -16,8 +17,8 @@ public class Build
public Output Output { get; set; }
public IEnumerable<String> IncludeTables { get; set; }
public IEnumerable<String> IgnoreTables { get; set; }
public bool IgnoreNoPKTable { get; set; }
public bool IgnoreView { get; set; }
public bool? IgnoreNoPKTable { get; set; }
public bool? IgnoreView { get; set; }
public NamingConverter NamingConverter { get; set; }
/// <summary>
/// 自定义构建参数
Expand Down
20 changes: 20 additions & 0 deletions src/SmartCode/Configuration/ConfigBuilders/ConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ protected void InitDefault()
buildTask.NamingConverter.Column = Project.NamingConverter.Column;
}
}

if (Project.TableFilter != null)
{
if (buildTask.IgnoreTables == null)
{
buildTask.IgnoreTables = Project.TableFilter.IgnoreTables;
}
if (buildTask.IncludeTables == null)
{
buildTask.IncludeTables = Project.TableFilter.IncludeTables;
}
if (!buildTask.IgnoreView.HasValue)
{
buildTask.IgnoreView = Project.TableFilter.IgnoreView;
}
if (!buildTask.IgnoreNoPKTable.HasValue)
{
buildTask.IgnoreNoPKTable = Project.TableFilter.IgnoreNoPKTable;
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/SmartCode/Configuration/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public class Project
public IDictionary<string, Build> BuildTasks { get; set; }
public String OutputPath => Output.Path;
public NamingConverter NamingConverter { get; set; }
public TableFilter TableFilter { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/SmartCode/Configuration/TableFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;

namespace SmartCode.Configuration
{
public class TableFilter
{
public IEnumerable<String> IncludeTables { get; set; }
public IEnumerable<String> IgnoreTables { get; set; }
public bool? IgnoreNoPKTable { get; set; }
public bool? IgnoreView { get; set; }
}
}

0 comments on commit 24ea67c

Please sign in to comment.