codegenerator
所属分类:SQL Server
开发工具:C#
文件大小:256KB
下载次数:0
上传日期:2021-11-26 22:16:03
上 传 者:
sh-1993
说明: iCodeGenerator是一个以数据库为中心的基于模板的代码生成器,适用于任何文本(ascii)编程语言,如C、P...
(iCodeGenerator is a database centric template based code generator for any text(ascii) programming language like C, PHP, C#, Visual Basic, Java, Perl, Python... Supported databases are SQL Server, MySQL and PostgreSQL.)
文件列表:
.editorconfig (94, 2023-07-08)
.vs (0, 2023-07-08)
.vs\CodeGenerator (0, 2023-07-08)
.vs\CodeGenerator\project-colors.json (1114, 2023-07-08)
.vs\iCodeGenerator (0, 2023-07-08)
.vs\iCodeGenerator\DesignTimeBuild (0, 2023-07-08)
.vs\iCodeGenerator\DesignTimeBuild\.dtbcache.v2 (8350, 2023-07-08)
.vs\iCodeGenerator\project-colors.json (2545, 2023-07-08)
.vs\iCodeGenerator\v17 (0, 2023-07-08)
.vs\iCodeGenerator\v17\.futdcache.v1 (415, 2023-07-08)
CodeGenerator.Shared (0, 2023-07-08)
CodeGenerator.Shared\AppVersion.cs (1260, 2023-07-08)
CodeGenerator.Shared\CodeGenerator.Shared.csproj (1852, 2023-07-08)
CodeGenerator.Shared\ConfigFile.cs (2274, 2023-07-08)
CodeGenerator.Shared\Data (0, 2023-07-08)
CodeGenerator.Shared\Data\DataSource.cs (111, 2023-07-08)
CodeGenerator.Shared\Data\ProviderFactory.cs (1359, 2023-07-08)
CodeGenerator.Shared\Data\Structure (0, 2023-07-08)
CodeGenerator.Shared\Data\Structure\Column.cs (685, 2023-07-08)
CodeGenerator.Shared\Data\Structure\DataSourceProvider (0, 2023-07-08)
CodeGenerator.Shared\Data\Structure\DataSourceProvider\BaseDataSourceProvider.cs (5078, 2023-07-08)
CodeGenerator.Shared\Data\Structure\DataSourceProvider\IDataSourceProvider.cs (388, 2023-07-08)
CodeGenerator.Shared\Data\Structure\DataSourceProvider\MySqlDataSourceProvider.cs (2309, 2023-07-08)
CodeGenerator.Shared\Data\Structure\DataSourceProvider\NpgsqlDataSourceProvider.cs (3521, 2023-07-08)
CodeGenerator.Shared\Data\Structure\DataSourceProvider\OracleDataSourceProvider.cs (4157, 2023-07-08)
CodeGenerator.Shared\Data\Structure\DataSourceProvider\SqlDataSourceProvider.cs (4954, 2023-07-08)
CodeGenerator.Shared\Data\Structure\Database.cs (1025, 2023-07-08)
CodeGenerator.Shared\Data\Structure\Key.cs (284, 2023-07-08)
CodeGenerator.Shared\Data\Structure\Server.cs (2225, 2023-07-08)
CodeGenerator.Shared\Data\Structure\Table.cs (1312, 2023-07-08)
CodeGenerator.Shared\Extensions (0, 2023-07-08)
CodeGenerator.Shared\Extensions\HumanizerExtensions.cs (510, 2023-07-08)
CodeGenerator.Shared\Extensions\StringExtensions.cs (249, 2023-07-08)
CodeGenerator.Shared\Generator (0, 2023-07-08)
CodeGenerator.Shared\Generator\Client.cs (2379, 2023-07-08)
CodeGenerator.Shared\Generator\Context.cs (304, 2023-07-08)
CodeGenerator.Shared\Generator\Expression.cs (976, 2023-07-08)
CodeGenerator.Shared\Generator\Expressions (0, 2023-07-08)
... ...
Code Generator
==============
Code Generator is a database centric template based code generator for any text(ascii) programming language like C, PHP, C#, Visual Basic, Java, Perl, Python... Supported databases are SQL Server, MySQL, PostgreSQL and Oracle.
## Screenshots
#### Simple Template:
#### Results:
## Documentation
### Database
- **{DATABASE.NAME}**
Placeholder for the database name.
- **{DATABASE.TABLES}...{/DATABASE.TABLES}**
Placeholder for the tables. Only used for iterating tables. Attempting to further iterate by columns will not work as you may expect.
### Table
- **{TABLE.SCHEMA}**
Placeholder for the table schema.
- **{TABLE.NAME}**
Placeholder for the table name.
- **{TABLE.COLUMNS}...{/TABLE.COLUMNS}**
Placeholder for the columns. Possible attributes are: PRIMARY, NOPRIMARY or ALL (default) to filter which columns to process.
### Columns
- **{COLUMN.NAME}**
Placeholder for the column's name.
- **{COLUMN.TYPE}**
Placeholder for the column's type.
- **{MAP COLUMN.TYPE}**
Placeholder for the selected programming language's data type mapped from the source database type. Configurable in the Config.js file.
- **{COLUMN.LENGTH}**
Placeholder for the column's length.
- **{COLUMN.DEFAULT}**
Placeholder for the column's default value.
### Conditional Statements
- **{IF COLUMN.NAME =~ ‘Id’}...{/IF}**
Condition to test if the name of the column contains a string.
- **{IF COLUMN.TYPE EQ ‘date|datetime|datetime2’}...{/IF COLUMN.TYPE}**
Condition to test if the type of the column is one of the specified database types.
- **{IF COLUMN.TYPE NE ‘date|datetime|datetime2’}...{/IF COLUMN.TYPE}**
Condition to test if the type of the column is NOT one of the specified database types.
- **{IF MAP COLUMN.TYPE EQ ‘DateTime’}...{/IF MAP COLUMN.TYPE}**
Condition to test if the data type mapped from the source database type of the column is one of the specified types.
- **{IF MAP COLUMN.TYPE NE ‘DateTime’}...{/IF MAP COLUMN.TYPE}**
Condition to test if the data type mapped from the source database type of the column is NOT one of the specified types.
- **{IF COLUMN.NULLCHECK NOT NULLABLE}...{/IF COLUMN.NULLCHECK}**
Condition to test if a column is nullable or not.
- **{IF COLUMN.LASTCHECK NOT LAST}...{/IF COLUMN.LASTCHECK}**
Condition to test if it is the last column being processed.
### Custom Values
- **{NAME_OF_YOUR_TAG}**
Custom Values are Key/Value Pairs that you can define to use in a template.
### Options
Some of the expressions allow for certain options to modify the output.
- **{COLUMN.NAME}**, **{DATABASE.NAME}** and custom values let you specify a case conversion. You can choose from any of the following: CAMEL, PASCAL, HUMAN, UNDERSCORE, UPPER, LOWER, HYPHEN, HYPHEN_LOWER, HYPHEN_UPPER. Example:
{COLUMN.NAME PASCAL}
- **{TABLE.NAME}** lets you specify multiple options. Here are some examples:
`{TABLE.NAME}`: Simply outputs the name, as it appears in the database
`{TABLE.NAME OPTIONS CASE=PASCAL}`: Converts the name to Pascal case
`{TABLE.NAME OPTIONS CASE=UPPER}`: Converts the name to Upper case
`{TABLE.NAME OPTIONS REPLACE(OldValue,NewValue)}`: An expression that allows you to replace a part of the table name with something. This can be useful if your table names tend to have a prefix. For example: `MyCompany_Sales`. To remove the prefix, use `{TABLE.NAME REPLACE(MyCompany_.,)}`
`{TABLE.NAME OPTIONS SINGULARIZE}`: Will ensure the table's name is singularized. Likewise, using `PLURALIZE` instead will pluralize the name.
Options can be combined, but must remain in the same order.. CASE, then REPLACE, then SINGULARIZE or PLURALIZE. Here's an example using all 3 options:
`{TABLE.NAME OPTIONS CASE=PASCAL REPLACE(MyCompany_,) SINGULARIZE}`
### Examples
```
using {Namespace}.Data.Domain;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace {Namespace}.Data
{
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions
options)
: base(options)
{
}
{DATABASE.TABLES}
public DbSet<{TABLE.NAME OPTIONS CASE=PASCAL}> {TABLE.NAME OPTIONS CASE=PASCAL} { get; set; }
{/DATABASE.TABLES}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
{DATABASE.TABLES}
builder.ApplyConfiguration(new {TABLE.NAME OPTIONS CASE=PASCAL}Map());{/DATABASE.TABLES}
}
}
}
```
```
using System;
using Extenso.Data.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace {Namespace}.Data.Domain
{
public class {TABLE.NAME OPTIONS CASE=PASCAL REPLACE(ABC_,) SINGULARIZE} : IEntity
{{TABLE.COLUMNS}
public {MAP COLUMN.TYPE} {COLUMN.NAME} { get; set; }
{/TABLE.COLUMNS}
#region IEntity Members
public object[] KeyValues
{
get { return new object[] { {TABLE.COLUMNS PRIMARY}{COLUMN.NAME}{/TABLE.COLUMNS} }; }
}
#endregion IEntity Members
}
public class {TABLE.NAME OPTIONS CASE=PASCAL}Map : IEntityTypeConfiguration<{TABLE.NAME OPTIONS CASE=PASCAL}>
{
public void Configure(EntityTypeBuilder<{TABLE.NAME OPTIONS CASE=PASCAL}> builder)
{
builder.ToTable("{TABLE.NAME}");
{TABLE.COLUMNS PRIMARY} builder.HasKey(m => m.{COLUMN.NAME});{/TABLE.COLUMNS}{TABLE.COLUMNS NOPRIMARY}
builder.Property(m => m.{COLUMN.NAME}).HasColumnType("{COLUMN.TYPE}"){IF COLUMN.NULLCHECK NOT NULLABLE}.IsRequired(){/IF COLUMN.NULLCHECK}.HasMaxLength({COLUMN.LENGTH}).IsUnicode(true);{/TABLE.COLUMNS}
}
}
}
```
### Additional Notes:
- If you name your templates using the `{TABLE.NAME...}` expression, it will automatically generate the correct file name for you as well. Examples:
```
{TABLE.NAME OPTIONS CASE=PASCAL}.cs
{TABLE.NAME OPTIONS CASE=PASCAL}Controller.cs
```
### Future Work:
It would be good to have the following work done in future:
- Separate the views from the tables.. example: {VIEW.COLUMNS...}, {VIEW.NAME...}, etc.
- Support for foreign key info, so that we can generate things like EF Navigation Properties
近期下载者:
相关文件:
收藏者: