使用xorm根据表信息生成model

本文介绍了如何使用xorm.io/reverse工具下载并配置YML文件,以自动化生成Golang模型,包括数据库连接信息和指定要包含的表。通过templates/tpl.yml模板,可以定制输出目录和文件结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载xorm.io/reverse

go get xorm.io/reverse

安装xorm.io/reverse

go install xorm.io/reverse

创建yml文件,文件内容

kind: reverse
name: grc
source:
  database: mysql
  conn_str: 'root:root@sec123@tcp(ip:端口)/grc?charset=utf8'
targets:
  - type: codes
    include_tables:
      - grc_button_list
      - grc_control_list
    multiple_files: true
    language: golang
    output_dir: model #输出的目录

通过yml生成model

reverse -f templates/tpl.yml(templates/tpl.yml为文件路径)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值