Reverse配置

Reverse配置

2023-07-13
reverse

MySQL表生成go语言(xorm)结构体的工具 reverse 的配置

kind: reverse
name: t_player
source:
  database: mysql
  conn_str: root:123456@tcp(127.0.0.1:3306)/db_log
targets:
  - type: codes
    include_tables: # 包含的表,以下可以用 **
      - t_report_room_record
    table_mapper: snake # 表名到代码类或结构体的映射关系
    column_mapper: snake # 字段名到代码或结构体成员的映射关系
    table_prefix: "" # 表前缀
    multiple_files: false # 是否生成多个文件
    table_name: true
    column_name: true
    language: golang
    output_dir: ./models # 代码生成目录
    template: | # template for code file, it has higher perior than 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}} json:"{{$col.Name}}"`
      {{end}}
      }
      
      func (m *{{TableMapper .Name}}) TableName() string {
        return "{{$table.Name}}"
      }
      
      var {{TableMapper .Name}}Columns = struct {
      {{range .ColumnsSeq}}{{$col := $table.GetColumn .}}   {{ColumnMapper $col.Name}} string
      {{end}}
      }{
      {{range .ColumnsSeq}}{{$col := $table.GetColumn .}}   {{ColumnMapper $col.Name}}: "{{$col.Name}}",
      {{end}}
      }
      {{end}}

大侠的赏赐,是我持续创作的动力,感谢!

微信公众号 赞赏码 赞赏码