This is a tool for Generate Your Code(all programming languages or maybatis map-files and so on, up to you) from database table definition. Befor using it, you need know how work it is. So please read this document and config this tool for your own projects by ".vscode/gyctools.config.json".
And if you like this tool,please give us a like.thanks.
Usage
Open Your Project First
- Patella will copy the default templates into ".vscode/gyc_templates" when you open the project if it doesn't exists.
- And Patella copy a particular config file "gyctools.config.json",you must edit it for your project folder construction.
Code Generator Entry
Generate Database Specification Entry
- It's on the database itemview when you right click, named "Generate DB Specification".
- And you can edit the specification.njk in the ".vscode" folder.
Features
1:generate all language from db table by Nunjucks template
2:generate database document by a default Nujucks template
How To Use
Every you named database can setting itself template info or other customs attributes
Every template can define is's own language interpreter
- Template can define is's own language interpreter by the attribute named "language'.
- If template not define language attribute gyc will auto catch it's value with 'outFileType'. But this only working with '.java','.ts' or '.cs' or not gyc will use default interpreter "xxSql to java".
Two kind instance take part in the Nunjucks template.CodeEntity and CodeProperty
1: CodeEntity is db table info, the properties can used in your template like this
{{dbType}}
{{tableName}}
{{className}}
{{primaryKey}}
...
Here is features for CodeEntity
//database type , currently we only support MySQL.this fiedl value samed with SQLTools driver name.
dbType: String;
//original table name from db
tableName: string;
//conversion from tableName
className: string;
//table's primary key
primaryKey?: string;
//table's auto increment column name
autoIncrementKey?: string;
//conversion from table columns
properties: Array<CodeProperty>;
//conversion from table columns
primarykeyProperties: Array<CodeProperty>;
//if the column conversion need import code, see TypeInterpreter Config
importArray: Array<string> = new Array<string>();
//custom attributes from config file
customsAttributes: any;
//table name prefix from config file
tableNamePrefix: string;
//total count of primary key
primaryKeyCount:number = 0;
//table's all primary key
primarykeyArray: Array<string>;
//table's all primary key translated to property
primaryKeyPropertyArray: Array<string>;
2: CodeProperty is table columns info, the properties can used in your template by {{properties}}:**
{% for property in properties %}
{% if property.isInBaseModel==false and property.columnName != primaryKey %}
private {{ property.propertyType }} {{ property.propertyName }};
{% endif %}
{% endfor %}
Here is features for CodeProperty
//table's column name
columnName: string;
//data type
dataType: string;
//data allowed null
isNullable: boolean;
//column is index and auto sequences
isAutoIncrement: boolean;
//column's comment info
comment: string;
//column is pk
isPrimaryKey: boolean = false;
//code(entity\pojo\object) field name translate from dataType
propertyName: string;
//code field type
propertyType?: string;
//code field methodName for java's get set function
methodName: string;
//code field need import/requir thirdparty class/object
importTypeName?: string;
//field is defined in base object
isInBaseModel: boolean = false;
Holding your self code in target files.
All codes were generated by templates , So self codes will be coverd by template result.Patella suport use commentary tag for retain you own codes.
// Add manual codes in patella holding range , they will be reserved when anthour generation.
//patella:holding codes name=myCodes
{{ holdingCode.myCodes }}
//patella:end holding codes
Extension Dependencies
If want use this tools,you must install SQLTools. It's a very popular extension for database manage.
Database Type supported
MySQL
Install SQLTools and SQLTools MySQL/MariaDB driver is necessarily.And the connection setting mast use 'Server and Port' and the password need select 'Save password' if not this tool can't connect to db server.
- Here is SQLtoos connection config sample
"sqltools.connections": [
{
"previewLimit": 50,
"server":"127.0.0.1",
"port": 3306,
"driver": "MySQL",
"name": "GYSTools",
"group": "GYSTools",
"database": "gyc_tools",
"username": "gyctools",
"password": "gyctools"
},
{
"mssqlOptions": {
"appName": "SQLTools",
"useUTC": true,
"encrypt": false
},
"previewLimit": 500,
"server": "127.0.0.1",
"port": 1433,
"driver": "MSSQL",
"name": "GYSTools",
"database": "GYSTools",
"username": "gyctools",
"password": "gyctools"
}
]
So EasyProducer-GYC need the username and password to connect the target databse.It's important use dev db not product to protect your information.
MsSQL
Install SQLTools and SQLTools MicrosoftSQL Server/Azure driver is necessarily. And the connection setting mast use 'Server and Port' and the password need select 'Save password' if not this tool can't connect to db server.
- Gyc config file is initialized in .vscode dictionary,file name is 'gyctools.config.json'. This means every project(root folder) has it's own settings.
- Befor use patella ,must fit the config file into your project.Such as 'outPath','customsAttributes' or 'customsTypeInterpreterConfig'
Code Template Info
Tools has a bundle of templates in extension installation directory "template-sqg-spring",it's a java-spring and a private template demo you to edit them for youself style. Alternatively,you can contact us help you for your own templates. And then you can set the template folder in gyctools.config by "dataBaseList.item.templatePath".
Language Type Interpreter
Gyc tool has tow type interpreter provided:
If that is not what your want,then can define a 'customsTypeInterpreterConfig' in 'gyctools.config.json' like the 'gyctools.config.json Demo'.
MySqlToJavaTypeInterpreter
static dbTypeToJavaTypeInterpreterConfig: any = {
'int': { 'result': 'Integer' },
'tinyint': { 'result': 'Integer' },
'smallint': { 'result': 'Integer' },
'datetime': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'timestamp': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'date': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'time': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'decimal': { 'result': 'BigDecimal', 'importTypeName': 'java.math.BigDecimal' },
'bit': { 'result': 'Boolean' },
'bigint': { 'result': 'Long' },
'default': { 'result': 'String' }
};
MsSqlToJavaTypeInterpreter
static dbTypeToJavaTypeInterpreterConfig: any = {
'int': { 'result': 'Integer' },
'tinyint': { 'result': 'Integer' },
'smallint': { 'result': 'Integer' },
'datetime': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'smalldatetime': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'timestamp': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'date': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'time': { 'result': 'Date', 'importTypeName': 'java.util.Date' },
'decimal': { 'result': 'BigDecimal', 'importTypeName': 'java.math.BigDecimal' },
'numeric': { 'result': 'BigDecimal', 'importTypeName': 'java.math.BigDecimal' },
'money': { 'result': 'BigDecimal', 'importTypeName': 'java.math.BigDecimal' },
'bit': { 'result': 'Boolean' },
'bigint': { 'result': 'Long' },
'default': { 'result': 'String' }
};
- leechzhao3@hotmail.com Looking Forward to Your Advice.