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.
- 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.
- 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.
1:generate all language from db table by Nunjucks template
2:generate database document by a default Nujucks template
- 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".
{{dbType}}
{{tableName}}
{{className}}
{{primaryKey}}
...
//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 %}
//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;
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
If want use this tools,you must install SQLTools. It's a very popular extension for database manage.
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.
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'
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".
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' } };
- [email protected] Looking Forward to Your Advice.