生成代码
Project description
gencode
gencode 代码生成工具,可以连接MySQL\Oracle\postgresql\sqlite根据jinjan2模板生成出自已想要的代码
安装
pip install gencode
使用方式
在模板文件所在的目录里执行
gendcode -c config.yml
配置文件
config.yml
# 模板文件地址
#templatePath: '/data'
dbConf:
# MySQL / Oracle / Sqlite / postgresql
db_type: MySQL
db_name: admin
user: admin
pwd: Vile123adMin_#
host: 127.0.0.1
# 多表使用;分割
table_name: sys_operator
# Java
dataTypeMapping:
varchar|text: String
decimal(10,2): int
# Python
#dataTypeMapping:
# default:
# varchar(*)|text: str
myself:
author: liuzhuo
mail: liuzhuogood@foxmail.com
sign: 我的签名
jinja2:
variable_start_string: '{{'
variable_end_string: '}}'
模板变量
变量 | 示例 | 说明 |
---|---|---|
XX_TABLE_NAME | SYS_BULLETIN_FILE | 表名变形 |
xx_table_name | sys_bulletin_file | 表名变形 |
XxTableName | SysBulletinFile | 表名变形 |
xxTableName | sysBulletinFile | 表名变形 |
TableName | BulletinFile | 表名变形 |
tableName | bulletinFile | 表名变形 |
table_name | bulletin_file | 表名变形 |
xx | sys | 表名变形 |
XX | SYS | 表名变形 |
date | 2021-10-11 | 当前日期 |
datetime | 2021-10-11 10:10:10 | 当前时间 |
author | liuzhuo | 名称 |
liuzhuogood@foxmail | 邮箱 | |
sign | 自动生成代码 | 签名 |
comment | 文件表 | 表备注 |
columns | <参考columns集合> | 列集合 |
columns集合
关键字 | 说明 |
---|---|
column_name | 列名变形 |
COLUMN_NAME | 列名变形 |
columnName | 列名变形 |
ColumnName | 列名变形 |
columnname | 列名变形 |
COLUMNAME | 列名变形 |
comment | 列名备注 |
dataType | 列名 的类型,可以通过配置映射 |
is_pk | 1:是主键 0:不是主键 |
方法
- ljust(str,[width],[fill_char]) : 左补全字符
- rjust(str,[width],[fill_char]) : 右补全字符
模板
模板可以是文件目录,也可是文件,如果是文件为了区分必须以.gcode
后缀命名,比如:
{{XxTableName}}Po.java.gcode
package {{xx}}
/**
{{comment}} 实体类
author: {{author}}
mail: {{mail}}
*/
public class {{TableName}}{
{% for c in columns %}
private {{c.dataType}} {{c.columnName}}; //{{c.comment}}
/**{{c.comment}}*/
public {{c.dataType}} get{{c.ColumnName}}(){return {{c.columnName}};};
/**{{c.comment}}*/
public void set{{c.ColumnName}}({{c.dataType}} {{c.columnName}}){this.{{c.columnName}}={{c.columnName}};};
{% endfor %}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
genCode-1.0.1.tar.gz
(8.3 kB
view details)
Built Distribution
genCode-1.0.1-py3-none-any.whl
(10.5 kB
view details)
File details
Details for the file genCode-1.0.1.tar.gz
.
File metadata
- Download URL: genCode-1.0.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1194e0cb8e2ab809da2d9b7968bd7d0bda260d2d28b77feee1b8d2952c5a56d0 |
|
MD5 | d9e0a4c1e58b53e88d6784b24312827b |
|
BLAKE2b-256 | 410c5b1a27a861bf967cc7aec1411717662c45ec9ae68c38068e95089854fa46 |
File details
Details for the file genCode-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: genCode-1.0.1-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f98423f9798eb21f051692583a95d9af9897f5b51cfbacefa3d14e1c6e70e89 |
|
MD5 | 45ee0d023f6430a09c695d7a87f97b05 |
|
BLAKE2b-256 | 4f574ff9c9ce1ac5196c15d264e403c7e51a6f556a5b5c783859fde43c9a1ff4 |