orm-generator

module
v0.0.0-...-d14b600 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: Apache-2.0

README

go-build

用于快速构建项目:

首先本克隆项目,到本地,然后

  • 构建脚本
./build.sh  
  • 查看命令
bin/go-build -h
  • 快速开始
bin/go-build -dir=/data/tmp -mod=ebike-city-report -git=git@gitee.com:Anthony-Dong/template.git

// 快速构建: -dir 项目本地位置 -mod 你的项目名称:go mod 的名称 ,本地版本不得 低于go 1.11 -git 是我的模版地址,会告诉你

orm-generator

用于生成Go的Model文件,数据库操作太过于麻烦,依靠工具可以直接生成model对象,默认使用的是xorm映射。

需要支持Go mod ,所以版本最好1.11以上

下载:

go get -u github.com/anthony-dong/orm-generator

执行
./build.sh

或者 release里下载压缩版

~/Downloads/orm-generator-1.0 % ls
LICENSE   README.md bin       build.sh  cmd       generator go.mod    go.sum    utils
~/Downloads/orm-generator-1.0 % ./build.sh
GOPATH: /Users/sgcx015/go
GOBIN: /Users/sgcx015/Downloads/orm-generator-1.0/bin/
CURDIR: /Users/sgcx015/Downloads/orm-generator-1.0
WORK=/var/folders/cs/_wm77lv95j5d88s_q9vr959w0000gn/T/go-build403299929
build finished
sgcx015@SGCX015deMacBook-Pro:~/Downloads/orm-generator-1.0 % bin/orm-generator

快速开始

~/go/code/orm-generator (master*) % bin/orm-generator -u=root -p=123456 -d=xorm -t=users -tag=xorm
generate template finished
~/go/code/orm-generator/tmp (master*) % cat tmp/users.go
package model

import (
	"time"
)

type Users struct {
	ID      uint32    `xorm:"id"`
	Name    string    `xorm:"name"`
	Age     uint32    `xorm:"age"`
	Date    time.Time `xorm:"date"`
	ClassID uint32    `xorm:"class_id"`
}

func (u Users) TableName() string {
	return "users"
}

命令行

~/go/code/orm-generator % bin/orm-generator -h
generator version: anthony/1.0.0
Usage: generator -T=mysql -n=xorm -host=localhost -port=3306 -u=root -p=123456 -t=class -t=student -tag=xorm -dir=/home/admin/tmp -package=model
Option:
  -T string
        database type, eg: -T=mysql (default "mysql")
  -c string
        database table names, eg: -c=utf8 (default "utf8")
  -d string
        database name, eg: -d=xorm (default "xorm")
  -debug
        open debug, eg:-debug
  -dir string
        generated directory default tmp, eg: -dir=/tmp (default "tmp")
  -h    this help
  -host string
        database host, eg: -port=localhost (default "localhost")
  -json
        model struct json tag default not add json tag, if add json, eg: -json
  -p string
        database password, eg: -p=123456 (default "123456")
  -package string
        package name default model, eg:-package=com.anthony.web.model (default "model")
  -port int
        database port, eg: -port=3306 (default 3306)
  -t value
        database table names, eg: -t=class -t=user
  -tag string
        model struct filed tag default xorm, eg: -tag=xorm (default "xorm")
  -u string
        database username, eg: -u=root (default "root")
  -v    generator version

Directories

Path Synopsis
cmd
orm

Jump to

Keyboard shortcuts

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