Code Monkey home page Code Monkey logo

reverse's Introduction

δΈ­ζ–‡

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}}
    }
    {{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.

reverse's People

Contributors

lunny avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.