md 生成目录 码云_doc_gf_tool_chain

# GoFrame工具链之代码生成

### 代码生成gen之model生成

现在gen命令主要是生成model

模型生成采用了`Active Record`设计模式。该命令将会根据数据表名生成对应的目录,该目录名称即数据表包名。目录下自动生成3个文件:

1. `数据表名.go` 自定义文件,开发者可以自由定义填充的代码文件,仅会生成一次,每一次模型生成不会覆盖。

2. `数据表名_entity.go` 表结构文件,根据数据表结构生成的结构体定义文件,包含字段注释。数据表在外部变更后,可使用`gen`命令重复生成更新该文件。

3. `数据表名_model.go` 表模型文件,为数据表提供了许多便捷的`CURD`操作方法,并可直接查询返回该表的结构体对象。数据表在外部变更后,可使用`gen`命令重复生成更新该文件。

```bash

D:\17.gfcli> gf gen -h

USAGE

gf gen model [PATH] [OPTION]

ARGUMENT

PATH the destination for storing generated files, not necessary, default is "./app/model"

OPTION

-l, --link database configuration, please refer to: https://goframe.org/database/gdb/config

-t, --table generate models only for given tables, multiple table names separated with ','

-g, --group used with "-c" option, specifying the configuration group name for database,

it's not necessary and the default value is "default"

-c, --config used to specify the configuration file for database, it's commonly not necessary.

If "-l" is not passed, it will search "./config.toml" and "./config/config.toml"

in current working directory in default.

-p, --prefix remove specified prefix of the table, multiple prefix separated with ','

EXAMPLES

gf gen model

gf gen model -l "mysql:root:12345678@tcp(127.0.0.1:3306)/test"

gf gen model ./model -l "mssql:sqlserver://sa:12345678@127.0.0.1:1433?database=test"

gf gen model ./model -c config.yaml -g user-center -t user,user_detail,user_login

gf gen model -p user_,p_

DESCRIPTION

The "gen" command is designed for multiple generating purposes.

It's currently supporting generating go files for ORM models.

PS D:\17.gfcli> gf gen model ./model -c config/config.toml -p sys_ -t sys_user

2020-04-26 23:35:31.682 [DEBU] [ 51 ms] SHOW FULL COLUMNS FROM `sys_user`

generated: ./model\user\user.go

generated: ./model\user\user_entity.go

generated: ./model\user\user_model.go

done!

D:\17.gfcli> tree /f .\model

卷 Data 的文件夹 PATH 列表

卷序列号为 DA91-D877

D:\17.GFCLI\MODEL

└─user

user.go

user_entity.go

user_model.go

```

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值