dotnetcore / smartcode Goto Github PK
View Code? Open in Web Editor NEWSmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything!!!
License: Apache License 2.0
SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything!!!
License: Apache License 2.0
pg 数据库有两个 schema ,public 和 geo , 都有一个名称为 water 的数据表, 两个表字段不相同, 遇到这种情况时, SmartCode.CLI 异常退出。
希望能够增加数据库 schema 的选项。
SmartCodeApp.Services和SmartCodeOptions.Services,还有SmartCode.TemplateEngine.Impl.OfficialRazorTemplateEngine,一个地方一个依赖注入容器,增加了代码阅读难度了,太凌乱了,建议大大整合一下。
抱拳了
表结构:
CREATE TABLE Sys_Area(
F_Id varchar(50) NOT NULL comment '标识列',
F_ParentId varchar(50) NULL comment '父级',
F_Layers int NULL comment '层次',
F_EnCode varchar(50) NULL comment '编码',
F_FullName varchar(50) NULL comment '名称',
F_SimpleSpelling varchar(50) NULL comment '简拼',
F_SortCode int NULL comment '排序码',
F_DeleteMark bit NULL comment '删除标志',
F_EnabledMark bit NULL comment '有效标志',
F_Description varchar(500) NULL comment '描述',
F_CreatorTime datetime NULL comment '创建日期',
F_CreatorUserId varchar(50) NULL comment '创建用户主键',
F_LastModifyTime datetime NULL comment '最后修改时间',
F_LastModifyUserId varchar(50) NULL comment '最后修改用户',
F_DeleteTime datetime NULL comment '删除时间',
F_DeleteUserId varchar(50) NULL comment '删除用户',
F_CreatorUserName varchar(50) NOT NULL DEFAULT '超级管理员',
F_DeleteUserName varchar(50) NULL,
F_LastModifyUserName varchar(50) NULL,
primary key (F_Id)
) ;
使用smartcode.yml默认设置,生成的Map里GetEntity把
。在获取数据时给出提示:Statement:SysArea.GetEntity Tag:Where Min-matched:1 but matched:0 fail.
使用SmartCode的过程中遇到很多问题:
1.不知道怎么建一个配置文件,因为一开始不知道安装目录下有一个SmartCode.yml,可以在这个文件的基础上改。另外也没说明安装目录在哪里
2.NamingConverter只考虑了需要改名的情况,如果不想改表名或者列名,应该怎么处理?
3.IncludeTables和IgnoreTables没有说明要用[ ]包起来,也没有例子
4......
总之最好每个配置项都要给出每种可能的值的例子。说白了就是
这个项目目前使用的还是 .Net Core 2.2 , 已经失去了官方的支持。 其中的原因, 已经在问题 #48 中讨论过了。
阻碍 SmartCode 继续升级最大的原因是使用了 Asp.Net Core Mvc 2.2 的视图引擎作为模板, 导致无法升级。
在我的 fork (https://github.com/beginor/smartcode)中, 已经将 Asp.Net Core Mvc 2.2 视图引擎替换为 https://github.com/adoconnection/RazorEngineCore , 还是 Razor , 还是 Cshtml , 语法也差不多, 但是不是 Asp.Net Core Mvc , 所以原来的模板无法使用, 所以就没有提交合并请求。
不知道还有多少人还再使用这个项目, 是否有人愿意一起来修改现有的模板呢, 凭我个人之力, 肯定无法完成全部模板的修改, 而且我不用这些模板。
这个项目能否继续发展, 需要大家一起努力。
简单说, 我可以提交合并请求, 把我的修改贡献出来,但是后果是现有的模板不能直接用, 需要同步修改全部模板。
Hi,
Whenever I run the generator command I get the following error:
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.2.0' was not found.
- The following frameworks were found:
2.1.24 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
3.1.11 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
5.0.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
I understand that it only support .NET 2.2.0, but wanted to ask if there's a way to change the target framework in the configuration file? Or it's 2.2.0 the only default option? I scrolled around the issues to figure if someone has asked this, but I couldn't understand..
Thank you...
SmartCode.Generator 代码生成器 计划新增 Java 项目脚手架模板,用于生成Java项目,有兴趣的同学踊跃报名。
Unhandled Exception: System.ComponentModel.Win32Exception: No such file or directory
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at SmartCode.App.BuildTasks.ProcessBuildTask.Build(BuildContext context) in C:\projects\smartcode\src\SmartCode.App\BuildTasks\ProcessBuildTask.cs:line 70
at SmartCode.App.ProjectBuilder.Build() in C:\projects\smartcode\src\SmartCode.App\ProjectBuilder.cs:line 54
at SmartCode.App.ProjectBuilder.Build() in C:\projects\smartcode\src\SmartCode.App\ProjectBuilder.cs:line 73
at SmartCode.App.SmartCodeApp.Run() in C:\projects\smartcode\src\SmartCode.App\SmartCodeApp.cs:line 103
at SmartCode.CLI.SmartCodeCommand.OnExecute() in C:\projects\smartcode\src\SmartCode.CLI\SmartCodeCommand.cs:line 37
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.InvokeAsync(MethodInfo method, Object instance, Object[] arguments)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](CommandLineContext context, CancellationToken cancellationToken)
at SmartCode.CLI.Program.Main(String[] args) in C:\projects\smartcode\src\SmartCode.CLI\Program.cs:line 17
at SmartCode.CLI.Program.
最近用到了PG数据库的物化表,发现在现有的生成器代码中查询数据库时没有包含物化视图,应该是修改 src/SmartCode.Generator/Maps/Database-PostgreSql.xml
文件中的 QueryTable
和 QueryColumn
两个查询。
但是目前还不知道如何查询物化视图的信息, 请问谁能给一些建议?
这个项目不错, 有点儿像当年的 CodeSmith , 请问怎么编写自定义 cshtml 模板?比如我要生成 NHibernate 或者 EF 的文件, 该怎么操作?
提交建议:希望像mybatis提供编写外部插件的功能,另外一个感谢昨天提供类图以供研究
经过几小时的努力, 终于可以让 SmartCode 的 ETL 运行起来了, 自动生成数据库定义和迁移配置,只要再手工检查和修改少量配置就可以直接运使用了, 当然这个是不可避免的。
有几点小小的建议, 希望能够采纳:
ETLTaskRepository
的连接串添加到 yml 配置, 现在要修改 appsettings.json
, 这个可以算是坑了;LoadBuildTask
的 PreCommand
和 PostCommand
改成数组, 参考 DataX 的 PreCommand
和 PostCommand
设置, 一个字符串写太长还是比较别扭的, 改一下更好;LoadBuildTask
增加一个一次插入多少行的配置, 分多次插入目标数据库, 现在应该是一次性全部插入目标数据库;另外, ETL yml 配置中的全局参数必须有一个 ETLTaskId
配置, 否则就直接抛异常退出, 搜索 SmartCode 的代码, 也不知道是做什么用的, 而且没有相关说明, 默认也没有生成这个配置。
Parameters:
ETLTaskId: 1
ETLCode: Mssql2PG.Info_Item
ETLRepository: PG
比如在批量删除场景下,我们需要多条件删除,如果传参对象在QueryParams均未匹配到,那么将会直接把整个表给清空
<Statement Id="Delete">
Delete From test
<Include RefId="QueryParams" />
</Statement>
_testService.Delete(new{xxid=1});
如果xxid没有在QueryParams中匹配到,test表里面的数据将全部被删除
SmartCode = IDataSource -> IBuildTask -> IOutput => Build Everything
SmartCode的执行流是 数据源->构建任务->输出,也就是说应用场景非常广泛。
SmartCode 插件机制拥有非常灵活的扩展能力,SmartCode 中一切都是插件。只要继承IPlugin接口即可,然后配置到appsettings.json,然后通过IPluginManager获取插件实例。
{
"Logging": {
"IncludeScopes": false,
"Console": {
"LogLevel": {
"Default": "Debug"
}
}
},
"SmartCode": {
"Version": "v1.7.0",
"Plugins": [
{
"Type": "SmartCode.IDataSource,SmartCode",
"ImplType": "SmartCode.Db.DbSource,SmartCode.Db"
},
{
"Type": "SmartCode.IBuildTask,SmartCode",
"ImplType": "SmartCode.App.BuildTasks.ClearBuildTask,SmartCode.App"
},
{
"Type": "SmartCode.IBuildTask,SmartCode",
"ImplType": "SmartCode.App.BuildTasks.MultiTemplateBuildTask,SmartCode.App"
},
{
"Type": "SmartCode.IBuildTask,SmartCode",
"ImplType": "SmartCode.Db.BuildTasks.BuildTask,SmartCode.Db"
},
{
"Type": "SmartCode.IBuildTask,SmartCode",
"ImplType": "SmartCode.Db.BuildTasks.ProjectBuildTask,SmartCode.Db"
},
{
"Type": "SmartCode.IOutput,SmartCode",
"ImplType": "SmartCode.App.Outputs.FileOutput,SmartCode.App"
},
{
"Type": "SmartCode.INamingConverter,SmartCode",
"ImplType": "SmartCode.Db.TableNamingConverter,SmartCode.Db"
},
{
"Type": "SmartCode.TemplateEngine.ITemplateEngine,SmartCode.TemplateEngine",
"ImplType": "SmartCode.TemplateEngine.Impl.HandlebarsTemplateEngine,SmartCode.TemplateEngine"
},
{
"Type": "SmartCode.TemplateEngine.ITemplateEngine,SmartCode.TemplateEngine",
"ImplType": "SmartCode.TemplateEngine.Impl.OfficialRazorTemplateEngine,SmartCode.TemplateEngine"
},
{
"Type": "SmartCode.Db.IDbTypeConverter,SmartCode.Db",
"ImplType": "SmartCode.Db.DbTypeConverter.DefaultDbTypeConverter,SmartCode.Db"
}
]
}
}
目前SmartCode支持俩种模板引擎 Razor & Handlebars 。
Razor 模板引擎使用的是官方版本,这一点上.NETer同学可以很轻松的自定义SmartCode模板,需要注意的是Razor模板的Model为BuildContext,具体方法可以参考源代码中的模板。编写完成之后放到RazorTemplates,构建时指定好即可。
SmartCode获取数据源结构使用的是SmartSql,所以SmartCode支持所有ADO.NET驱动相关的数据库:MySql/PostgreSql/SqlServer/Oracle/SQLite 等
We want to use SmartCode to extend a static website generator. What do you think?
什么时候升级到.netcore3.1啊?
目前SmartCode生成的代码,在联合主键的表格中都是简单将第一列当成主键形式生成的,是否可以支持生成一个联合主键列构成的简单封装来作为主键参数?
为了让更多人参与到SmartCode模板建设中来,故有以下模板规范:
MySql.Data 8.0.19 无法识别information_schema utf8mb3字符集, 需要更新到最新版本8.0.29
Delete From @table.Name
Where @pkCol.Name=@[email protected]
DbTypeMap.xml中没有关于mysql的enum类型的映射
最近又要用到这个模板生成了, 针对 pg 数据库启用 postgis 扩展之后, 运行 SmartCode 时报错, 提示如下:
fail: SmartCode.Generator.DbTypeConverter.DefaultDbTypeConverter[0]
Can not find DatabaseMap:DbProvider:PostgreSql,Language:CSharp,DbType:name!
这个错误可以在
src/SmartCode.Generator/DbTypeConverter/DbTypeMap.xml
中增加对应的数据库类型来解决, 但是项目中没有用到这个name
数据类型。
经过几百行的输出之后, 再次提示:
dbug: SmartCode.App.PluginManager[0]
GetPlugin Name:Razor,PluginType:SmartCode.TemplateEngine.ITemplateEngine,ImplType:SmartCode.TemplateEngine.Impl.OfficialRazorTemplateEngine!
Unhandled Exception: System.InvalidOperationException: Sequence contains no elements
at SmartCode.CLI.Program.Main(String[] args) in /Users/zhang/Projects/smart-code/smart-code/src/SmartCode.CLI/Program.cs:line 53
at SmartCode.CLI.Program.<Main>(String[] args)
删除 postgis
扩展之后, 则一切正常。
貌似 SmartCode 还不能将 pg 数据库的表/视图描述查询出来, 通过下面的语句可以查询出表/视图的描述, 希望能够加入到 SmartCode 的代码中,不知道有没有错误, 希望再检查一下。
(SELECT
T.tablename AS "Name",
'T' AS "TypeName",
obj_description(C.oid) As "Description"
FROM
pg_tables T
left join pg_class C on C.relname = T.tablename and C.relkind = 'r'
WHERE
schemaname = @DbSchema)
UNION ALL
(SELECT
V.viewname AS "Name",
'V' AS "TypeName",
obj_description(C.oid) as "Description"
FROM
pg_views V
left join pg_class C on C.relname = V.viewname and C.relkind = 'v'
WHERE
schemaname = @DbSchema)
SmartCode生成代码的时候,由于我们数据库的字段都是大写。
所以生成出来的字段名称变成了类似下面这个样:
有没有什么办法可以设置,名字是驼峰的~
<ResultMap Id="ShippingOrderResultMap">
<Result Column="WH_ID" Property="WHID" />
<Result Column="SHIPPING_ORDER_ID" Property="SHIPPINGORDERID" />
<Result Column="OWNER_ID" Property="OWNERID" />
<Result Column="ORDER_STATUS_SC" Property="ORDERSTATUSSC" />
数据库命名规范:单词大写+下划线
期望输出:转化之后的映射字段命名是 类似:OwnerId 而非 OWNERID。
请问现在 SmartCode 支持 TypeScript 的类型系统么? 打算 SmartCode 做一套基于 Angular 的增删查改的模板, 如果有的话就可以直接使用了。
当表描述中包含换行符,比如:
EXEC sp_addextendedproperty N'MS_Description', N'线路表
记录线路的名称,创建者等等', 'SCHEMA', N'dbo', 'TABLE', N'MS20_Route', NULL, NULL
生成对应的实体类为:
namespace SmartSql.Starter.Entity
{
///
///线路表
记录线路的名称,创建者等
///
public class MS20Route
{ }
}
看了 SmartCode.Db.Entity. Column
的定义, 貌似不支持数据表的外键关系,是这样么?
支持一对多,多对多的生成吗?支持自定义sql语句吗?我想利用你这个开发一个低代码工具
刚好有张测试表, 表结构为
-- Table: public.test_table
-- DROP TABLE public.test_table;
CREATE TABLE public.test_table
(
id integer NOT NULL DEFAULT nextval('test_table_id_seq'::regclass),
name character varying(32) COLLATE pg_catalog."default" NOT NULL,
tags character varying(32)[] COLLATE pg_catalog."default",
json_field json,
jsonb_field jsonb,
update_time timestamp without time zone,
int32_arr integer[],
int16_arr smallint[],
int64_arr bigint[],
real_arr real[],
double_arr double precision[],
bool_arr boolean[],
long_field bigint,
CONSTRAINT pk_test_table PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.test_table
OWNER to postgres;
COMMENT ON TABLE public.test_table
IS 'test table';
用 SmartCode 生成的实体类如下:
//*******************************
// Create By Ahoo Wang
// Date 2018-10-19 13:24
// Code Generate By SmartCode
// Code Generate Github : https://github.com/Ahoo-Wang/SmartCode
//*******************************
using System;
namespace SmartSql.Starter.Entity
{
///<summary>
///TestTable
///</summary>
public class TestTable
{
///<summary>
///Id
///</summary>
public int Id { get; set; }
///<summary>
///Name
///</summary>
public string Name { get; set; }
///<summary>
///Tags
///</summary>
public ? Tags { get; set; }
///<summary>
///JsonField
///</summary>
public string JsonField { get; set; }
///<summary>
///JsonbField
///</summary>
public string JsonbField { get; set; }
///<summary>
///UpdateTime
///</summary>
public DateTime? UpdateTime { get; set; }
///<summary>
///Int32Arr
///</summary>
public ? Int32Arr { get; set; }
///<summary>
///Int16Arr
///</summary>
public ? Int16Arr { get; set; }
///<summary>
///Int64Arr
///</summary>
public ? Int64Arr { get; set; }
///<summary>
///RealArr
///</summary>
public ? RealArr { get; set; }
///<summary>
///DoubleArr
///</summary>
public ? DoubleArr { get; set; }
///<summary>
///BoolArr
///</summary>
public ? BoolArr { get; set; }
///<summary>
///LongField
///</summary>
public long? LongField { get; set; }
}
}
官方的Entity, Service,Repository的类里,都默认成partial类吧,方便扩展,自己的代码都加到partial类里,重新生成,也不会影响自己的partial类
当前的模板中, 是使用Top进行获取数据。
`
<Statement Id="Query" @queryStatementResultMap>
SELECT
<IsNotEmpty Prepend="Top" Property="Taken">
(@(dbPrefix)Taken)
</IsNotEmpty>
T.* From @table.Name T
<Include RefId="QueryParams" />
<Switch Prepend="Order By" Property="OrderBy">
<Default>
[email protected] Desc
</Default>
</Switch>
</Statement>
`
但是实际上, oracle不支持top的语法。建议调整如下:
`
<Statement Id="Query" @queryStatementResultMap>
select * from (
SELECT
T.* From @table.Name T
<Include RefId="QueryParams"/>
<Switch Prepend="Order By" Property="OrderBy">
<Default>
[email protected] Desc
</Default>
</Switch>
)
<IsNotEmpty Prepend="where" Property="Taken">
ROWNUM < (@(dbPrefix)Taken)
</IsNotEmpty>
</Statement>
`
利用Roslyn分析c#源码文件中的实体类、属性等元数据,生成Service层、Repository层、以及SmartSql xml文件,并且执行数据库创建脚本。
哪有教程教怎么写模板,好让我们贡献出来
首先谢谢 @Ahoo-Wang 写的这个非常好用的工具,有个小问题,当我设置NamingConverter: Camel时,所有词都变成小写了,
问题应该出在这一行
https://github.com/Smart-Kit/SmartCode/blob/93ecc932900220f2b7d4f723cad39e42c6ba5589/src/SmartCode/WordsConverter/CamelCaseConverter.cs#L20
如题, 请问能否考虑将 IncludeTables
IgnoreTables
IgnoreNoPKTable
IgnoreView
这些属性添加到全局配置。
多数情况下每个 Build 下的 Task 的配置是相同的, 现在是每个 Task 都要写这些配置, 修改起来比较麻烦。
Task 默认读取全局的这些配置, 如果 Task 下重新定义了这些属性, 则IncludeTables
IgnoreTables
可以和全局定义的进行合并,IgnoreNoPKTable
IgnoreView
则以 Task 的配置为准。
Version
:'3.0.1'
System.TypeLoadException
HResult=0x80131522
Message=Could not load type 'SmartCode.OnProjectBuildStartupHandler' from assembly 'SmartCode, Version=3.0.1.0, Culture=neutral, PublicKeyToken=null'.
Source=SmartCode.App
StackTrace:
在 SmartCode.App.ProjectBuilder.<Build>d__13.MoveNext()
在 System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
在 SmartCode.App.ProjectBuilder.Build()
在 SmartCode.App.SmartCodeApp.<Run>d__29.MoveNext()
在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
在 Bing.CodeGenerator.Console.Program.<Main>d__3.MoveNext() 在 H:\Bing_Framework\Bing.CodeGenerator\src\Bing.CodeGenerator.Console\Program.cs 中: 第 52 行
此异常最初是在此调用堆栈中引发的:
[外部代码]
Bing.CodeGenerator.Console.Program.Main(string[]) (位于 Program.cs 中)
如题, 建议为 Output 的文件名增加 Converter 设置。
比如数据库表名为 app_user
, 在生成前端 ts 代码时, 需要保存为 app-user.model.ts
, 可以更好的遵循前端开发的代码规范。
如果有 Schema 可以实现 Schema.Domain 该方式
类似vue3.0 ui用此管理模板,后续还能支持界面生成
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.