Skip to main content

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 名称
mail 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 %}

}

Metadata

Release files for genCode 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for genCode 1.0.1
File Size Uploaded Provenance
genCode-1.0.1.tar.gz 8.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for genCode 1.0.1
File Interpreter ABI Platform
genCode-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / genCode-1.0.1.tar.gz

Download URL genCode-1.0.1.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1194e0cb8e2ab809da2d9b7968bd7d0bda260d2d28b77feee1b8d2952c5a56d0
BLAKE2b-256 checksum
How to use checksums
410c5b1a27a861bf967cc7aec1411717662c45ec9ae68c38068e95089854fa46
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / genCode-1.0.1-py3-none-any.whl

Download URL genCode-1.0.1-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f98423f9798eb21f051692583a95d9af9897f5b51cfbacefa3d14e1c6e70e89
BLAKE2b-256 checksum
How to use checksums
4f574ff9c9ce1ac5196c15d264e403c7e51a6f556a5b5c783859fde43c9a1ff4
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for genCode 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page