db2struct

command module
v0.0.0-...-053c7d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2020 License: MIT Imports: 9 Imported by: 0

README

db2struct Documentation

点我查看中文版

1, About

  • A tool for change database(mysql) struct to go struct

2, Overview

  • Change table struct to golang struct
  • Support multiple output config

3, Getting Started

  • go get -u github.com/wnote/db2struct

  • Edit config.json

    cd /path/to/wnote/db2struct

    vi config.json
    {
      "db_type":   "mysql",
      "file_mode": "0777",
      "out_conf_list":[
        {
          "table_prefix": "pjt_",
          "db_dn":        "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=true&loc=Local",
          "output_dir":  "./model/test",
          "select_tables":["project.*"],
          "model_package":"test_package",
          "exclude_fields":"id,create_time"
        }
      ]
    }
    
    db_type: current only support mysql
    file_mode: output file permission
    out_conf_list: model output config list
       table_prefix: If all table has prefix ,then set it,otherwise fill blank
       db_dn: mysql connection db
       output_dir: model output dir
       select_tables: null is default,  all table will output the models
                      // regexp,default is all table in this database
       exclude_fields:ignore some fields when generate struct
    
    Simple config.json
       ```json
       {
         "out_conf_list":[
           {
             "db_dn":        "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8&parseTime=true&loc=Local",
             "output_dir":  "./model/test",
           }
         ]
       }
      ```
    
  • Configure example

    config.json Example

    Template Example

  • Run tools

    // default is ./config.json
    go run main.go
    // Ts has default template in config/default_template.go
    go run main.go -c ./config.json 
    go run main.go -c ./config.json -t example_model.tpl
    

4, Contributing

You can send pull request to deliver a better db2struct

Contributor

5, License

© wnote, 2018~time.Now

Released under the MIT License

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL