美文网首页
xorm工具reverse使用教程

xorm工具reverse使用教程

作者: 夜空最亮的9星 | 来源:发表于2023-11-08 18:20 被阅读0次

下载

https://gitea.com/xorm/reverse

编译打包

go build -o reverse main.go

放入gopath目录下;

验证:

reverse -v
reverse version 0.1+dev

新建 custom.yml 内容如下:


kind: reverse
name: mydb
source:
  database: mysql
  conn_str: 'root:123456@tcp(192.168.0.201:3306)/test?charset=utf8'
targets:
  - type: codes
    language: golang
    table_prefix: "" # 表前缀
    multiple_files: true # 是否生成多个文件
    template: | # 生成模板,如果这里定义了,优先级比 template_path 高
      package models
      
      {{$ilen := len .Imports}}
      {{if gt $ilen 0}}
      import (
        {{range .Imports}}"{{.}}"{{end}}
      )
      {{end}}
      
      {{range .Tables}}
      type {{TableMapper .Name}} struct {
      {{$table := .}}
      {{range .ColumnsSeq}}{{$col := $table.GetColumn .}}   {{ColumnMapper $col.Name}}  {{Type $col}} `{{Tag $table $col}}`
      {{end}}
      }
      {{end}}
    output_dir: ./models # 代码生成目录


执行命令:

reverse -f .\custom.yml

本地models目录下生成结构OK;

pg.yml

kind: reverse
name: mydb
source:
  database: postgres
  conn_str: 'postgres://postgres:123456@192.168.0.201:5432/test_db?sslmode=disable'
targets:
  - type: codes
#    include_tables:
#      - tb_user
#      - tb_order
#    exclude_tables:
#          - place
#          - person
    language: golang
    table_prefix: "" # 表前缀
    multiple_files: true # 是否生成多个文件
    template: | # 生成模板,如果这里定义了,优先级比 template_path 高
      package models
      
      {{$ilen := len .Imports}}
      {{if gt $ilen 0}}
      import (
        {{range .Imports}}"{{.}}"{{end}}
      )
      {{end}}
      
      {{range .Tables}}
      type {{TableMapper .Name}} struct {
      {{$table := .}}
      {{range .ColumnsSeq}}{{$col := $table.GetColumn .}}   {{ColumnMapper $col.Name}}  {{Type $col}} `{{Tag $table $col}}`
      {{end}}
      }
      {{end}}
    output_dir: ./models5 # 代码生成目录

相关文章

  • 使用xorm的reverse指令创建model

    编译xorm包 需要安装的依赖包: 命令格式 1、格式xorm reverse <数据库驱动名称><数据库连接字符...

  • go xorm cmd工具使用

    安装go-sql-driver/mysql 安装xorm 安装xorm的cmd命令工具 找到xorm安装的目录 进...

  • XORM使用的坑

    xorm使用in : 使用SQL后使用Limit可能不生效,最好使用where 结构体自动忽略空字段在xorm中,...

  • Go ORM框架XORM事务的示例

    说明 XORM文档 xorm-plus,xorm的增强版本,支持嵌套式事务 使用的是sqlite数据库 语句orm...

  • xorm reverse 采坑日记

    1 安装 xorm 工具 2 验证是否安装成功 3 在项目的src目录下建立一个models文件夹4 找到reve...

  • xorm使用

    定义关系模型 关系说明:(逻辑外键在子表上) 教师表(子表)1:教师详细表(主表)1 课程表(子表)N:教师表(主...

  • XORM执行SQL()的坑 2021-10-09

    xorm是一个Go语言ORM库 今天在使用过程中踩坑了,特此记录 使用func (*xorm.Session).S...

  • golang-MySql

    一、mySql连接 1、引入驱动包和xorm import "github.com/go-xorm/xorm" i...

  • 生物科研数据库使用教程

    TCGA数据库使用教程 Oncomine数据库使用教程 GEO数据库使用教程及在线数据分析工具 KEGG数据库使用...

  • 招聘广告 banner 制作

    使用工具 sketch photoshop keynote 教程 待续

网友评论

      本文标题:xorm工具reverse使用教程

      本文链接:https://www.haomeiwen.com/subject/azbqwdtx.html