A flexsible and powerful command line tool to convert database to codes
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Jerry d29e5a0fd3 fix UT case (#17) 1 semana atrás
cmd fix UT case (#17) 1 semana atrás
example template add generate TableName() func (#13) 1 semana atrás
language remove col.FieldName (#15) 1 semana atrás
testdata init project 6 meses atrás
vendor upgrade xorm to v1.0.0 (#10) 3 meses atrás
.drone.yml store vendors on git 5 meses atrás
.gitignore fix lint 5 meses atrás
LICENSE init project 6 meses atrás
README.md template add generate TableName() func (#13) 1 semana atrás
README_CN.md update readme 5 meses atrás
go.mod upgrade xorm to v1.0.0 (#10) 3 meses atrás
go.sum upgrade xorm to v1.0.0 (#10) 3 meses atrás
main.go fix lints 5 meses atrás

README.md

中文

Build Status

Reverse

A flexsible and powerful command line tool to convert database to codes.

Installation

go get xorm.io/reverse

Usage

reverse -f example/custom.yml

Configuration File

How does the simplest configuration file look like?

kind: reverse
name: mydb
source:
  database: sqlite3
  conn_str: '../testdata/test.db'
targets:
- type: codes
  language: golang
  output_dir: ../models

A language defines some default configuration items, also you can define all yourselves.

kind: reverse
name: mydb
source:
  database: sqlite
  conn_str: ../testdata/test.db
targets:
- type: codes
  include_tables: # tables included, you can use **
    - a
    - b
  exclude_tables: # tables excluded, you can use **
    - c
  table_mapper: snake # how table name map to class or struct name
  column_mapper: snake # how column name map to class or struct field name
  table_prefix: "" # table prefix
  multiple_files: true # generate multiple files or one
  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}}`
    {{end}}
    }

    func (m *{{TableMapper .Name}}) TableName() string {
    	return "{{$table.Name}}"
    }
    {{end}}
  template_path: ./template/goxorm.tmpl # template path for code file, it has higher perior than template field on language
  output_dir: ./models # code output directory

Template Funcs

  • UnTitle: Convert first charator of the word to lower.
  • Upper: Convert word to all upper.
  • TableMapper: Mapper method to convert table name to class/struct name.
  • ColumnMapper: Mapper method to convert column name to class/struct field name.

Template Vars

  • Tables: All tables.
  • Imports: All imports needed.