Code Monkey home page Code Monkey logo

gormt's Introduction

Build Status Go Report Card GoDoc Mentioned in Awesome Go

mysql database to golang struct conversion tools base on gorm(v1/v2),You can automatically generate golang sturct from mysql database. big Camel-Case Name Rule, JSON tag.

gui support

show

./gormt -g=true

cmd support

show

./gormt -g=false

install

go get -u -v github.com/xxjwxc/gormt@latest

or: Dowloading


1. Configure default configuration items through the current directory config.yml file

note: for latest version of config format, please check /data/config/MyIni.go

out_dir : "./model"  # out dir
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
language :  # language(English,中 文)
db_tag : gorm # DB tag(gorm,db)
simple : false #simple output
is_out_sql : false # Whether to output sql
is_out_func : true # Whether to output function
is_foreign_key : true # Whether to mark foreign key or not
is_gui : false # Whether to operate on gui
is_table_name : false # Whether to out GetTableName/column function
is_null_to_point : false # database is 'DEFAULT NULL' then set element type as point
is_web_tag: false
is_web_tag_pk_hidden: false
table_prefix: "" #table prefix
table_names: "" # Specified table generation, multiple tables with , separated
is_column_name: true # Whether to generate column names
is_out_file_by_table_name: false # Whether to generate multiple models based on table names
db_info :
    host : "127.0.0.1"
    port : 3306
    username : "root"
    password : "qwer"
    database : "oauth_db"
    type: 0 # database type (0:mysql , 1:sqlite , 2:mssql)
self_type_define: # Custom data type mapping
    datetime: time.Time
    date: time.Time
out_file_name: "" # Custom build file name
web_tag_type: 0 # json tag 0: Small Camel-Case 1: _

2. get help

./gormt --help
or
./gormt -h

-------------------------------------------------------
base on gorm tools for mysql database to golang struct

Usage:
  main [flags]

Flags:
  -d, --database string   数据库名
  -f, --foreign           是否导出外键关联
  -F, --fun               是否导出函数
  -g, --gui               是否ui显示模式
  -h, --help              help for main
  -H, --host string       数据库地址.(注意-H为大写)
  -o, --outdir string     输出目录
  -p, --password string   密码.
      --port int          端口号 (default 3306)
  -s, --singular          是否禁用表名复数
  -b, --table_names string 表名称  
  -l, --url string        url标签(json,url)
  -u, --user string       用户名.
  

3. Can be updated configuration items using command line tools

./gormt -H=127.0.0.1 -d=oauth_db -p=qwer -u=root --port=3306 -F=true

4. Support for gorm attributes

  • Database tables, column field annotation support
  • json tag json tag output
  • gorm.Model Support export gorm.model>>>
  • PRIMARY_KEY Specifies column as primary key
  • UNIQUE Specifies column as unique
  • NOT NULL Specifies column as NOT NULL
  • INDEX Create index with or without name, same name creates composite indexes
  • UNIQUE_INDEX Like INDEX, create unique index
  • Support foreign key related properties Support export gorm.model>>>
  • Support function export (foreign key, association, index , unique and more)Support export function >>>
  • model.Condition{} sql link

You can enrich data types in def

5. Demonstration

  • sql:
CREATE TABLE `user_account_tbl` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `account` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `password` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `account_type` int(11) NOT NULL DEFAULT '0' COMMENT '帐号类型:0手机号,1邮件',
  `app_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'authbucket_oauth2_client表的id',
  `user_info_tbl_id` int(11) NOT NULL,
  `reg_time` datetime DEFAULT NULL,
  `reg_ip` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `bundle_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `describ` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `account` (`account`) USING BTREE,
  KEY `user_info_id` (`user_info_tbl_id`) USING BTREE,
  CONSTRAINT `user_account_tbl_ibfk_1` FOREIGN KEY (`user_info_tbl_id`) REFERENCES `user_info_tbl` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='用户账号'
--->Derived results
// UserAccountTbl 用户账号
type UserAccountTbl struct {
	ID            int    `gorm:"primary_key"`
	Account       string `gorm:"unique"`
	Password      string
	AccountType   int         // 帐号类型:0手机号,1邮件
	AppKey        string      // authbucket_oauth2_client表的id
	UserInfoTblID int         `gorm:"index"`
	UserInfoTbl   UserInfoTbl `gorm:"association_foreignkey:user_info_tbl_id;foreignkey:id"` // 用户信息
	RegTime       time.Time
	RegIP         string
	BundleID      string
	Describ       string
}

6. support func export

The exported function is only the auxiliary class function of Gorm, and calls Gorm completely

// FetchByPrimaryKey primary or index 获取唯一内容
func (obj *_UserAccountTblMgr) FetchByPrimaryKey(ID int) (result UserAccountTbl, err error) {
	err = obj.DB.Table(obj.GetTableName()).Where("id = ?", ID).Find(&result).Error
	if err == nil && obj.isRelated {
		{
			var info UserInfoTbl // 用户信息
			err = obj.DB.Table("user_info_tbl").Where("id = ?", result.UserInfoTblID).Find(&info).Error
			if err != nil {
				return
			}
			result.UserInfoTbl = info
		}
	}

	return
}

7. page

8. build

make windows
make linux
make mac

or

go generate

note : in windows not support utf-8 style . ASCALL model

  • Switch encoding mode
CHCP 65001 

column notes default

  • Add a comment to the column starting with [@gorm default:'test']
  • example [@gorm default:'test';->;<-:create]this is my notes Indicates that the default value is 'test',can read/creat/write
  • Use of foreign key notes[@fk tableName.columnName]this is my notes Represents the 'columnName' column associated with the 'tableName'

9. one windows gui tools

1

2

3

4

Download

Stargazers over time

Stargazers over time

gormt's People

Contributors

15ho avatar android-coco avatar bingbingtea avatar crabmany avatar dependabot[bot] avatar evildao avatar fchange avatar fyyang avatar gh73962 avatar gracece avatar jeffmingup avatar jiang4869 avatar jianjungki avatar llllancelot avatar ly258liuyue avatar mrvokia avatar nanfangstation avatar panol avatar pengwenwu avatar rellopn avatar ruixule avatar snowlyg avatar swmiao1 avatar taobaohi avatar viwii avatar wclssdn avatar windha avatar xxjwxc avatar yilianhudong avatar zilinyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gormt's Issues

如果表太多,内存不足

`panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1385c66]

goroutine 1 [running]:
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0000a2d00, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0005078c0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc000507d60, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0006ffb80, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0006ffd00, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0006ffd60, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0007012e0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0003f2c20, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0005581a0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc000558420, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0003f2e80, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc000701ee0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc00052e300, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0003f36e0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc000558e40, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc000559560, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0003f3980, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc000428080, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0003f3e80, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
panic(0x14d4fc0, 0x1a1eea0)
/usr/local/Cellar/go/1.12.8/libexec/src/runtime/panic.go:522 +0x1b5
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2976 +0x66
database/sql.(*Rows).Close(0x0, 0xc0004282c0, 0x0)
/usr/local/Cellar/go/1.12.8/libexec/src/database/sql/sql.go:2972 +0x33
`

报错了。type (int unsigned) not match in any way.maybe need to add on (https://github.com/xxjwxc/gormt/blob/master/data/view/cnf/def.go)

panic: type (int unsigned) not match in any way.maybe need to add on (https://github.com/xxjwxc/gormt/blob/master/data/view/cnf/def.go)

goroutine 1 [running]:
github.com/xxjwxc/gormt/data/view/model.getTypeName(0xc000392c14, 0xc, 0x1607886, 0x1)
/Users/eric/Downloads/gormt-3.0.3/data/view/model/common.go:51 +0x218
github.com/xxjwxc/gormt/data/view/model.(_Model).genTableElement(0xc000375c10, 0xc00024f500, 0x7, 0x8, 0x1, 0xc0004310e0, 0x0)
/Users/eric/Downloads/gormt-3.0.3/data/view/model/model.go:81 +0xd14
github.com/xxjwxc/gormt/data/view/model.(
_Model).GetPackage(0xc000375c10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/eric/Downloads/gormt-3.0.3/data/view/model/model.go:53 +0x23d
github.com/xxjwxc/gormt/data/view/model.(*_Model).generate(0xc000375c10, 0xc00017d030, 0x9)
/Users/eric/Downloads/gormt-3.0.3/data/view/model/model.go:65 +0x3e
github.com/xxjwxc/gormt/data/view/model.Generate(0xc00017d0a0, 0x7, 0xc00017cd9a, 0x5, 0xc00037e900, 0xb, 0x10, 0x10, 0xc, 0xb, ...)
/Users/eric/Downloads/gormt-3.0.3/data/view/model/model.go:31 +0xc3
github.com/xxjwxc/gormt/data/view/gtools.showCmd()
/Users/eric/Downloads/gormt-3.0.3/data/view/gtools/gtools.go:36 +0xb7
github.com/xxjwxc/gormt/data/view/gtools.Execute()
/Users/eric/Downloads/gormt-3.0.3/data/view/gtools/gtools.go:21 +0x38
github.com/xxjwxc/gormt/data/cmd.glob..func1(0x1b39260, 0xc00030b540, 0x0, 0x1)
/Users/eric/Downloads/gormt-3.0.3/data/cmd/cmd.go:30 +0x20
github.com/spf13/cobra.(*Command).execute(0x1b39260, 0xc0000c4030, 0x1, 0x1, 0x1b39260, 0xc0000c4030)
/Users/eric/GoProject/GoResource/pkg/mod/github.com/spf13/[email protected]/command.go:830 +0x2aa
github.com/spf13/cobra.(*Command).ExecuteC(0x1b39260, 0x0, 0x0, 0x0)
/Users/eric/GoProject/GoResource/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
/Users/eric/GoProject/GoResource/pkg/mod/github.com/spf13/[email protected]/command.go:864
github.com/xxjwxc/gormt/data/cmd.Execute()
/Users/eric/Downloads/gormt-3.0.3/data/cmd/cmd.go:38 +0x2d
main.main()
/Users/eric/Downloads/gormt-3.0.3/main.go:6 +0x20

不支持smallint类型

{"Host":"127.0.0.1","Port":3306,"Username":"root","Password":"123456","Database":"xjaccountsdb"}
panic: type (smallint(6)) not match in any way.maybe need to add on ()

一直生成失败,这是啥还有python问题?


goroutine 1 [running]:
github.com/xxjwxc/gormt/data/view/model.getTypeName(0xc000028cb0, 0x8, 0x1570c25, 0x1)
	/Users/Django/www/tools/gormt/data/view/model/common.go:47 +0x218
github.com/xxjwxc/gormt/data/view/model.(*_Model).genTableElement(0xc000565cd0, 0xc000238700, 0x7, 0x8, 0xc000551180, 0xb, 0x10)
	/Users/Django/www/tools/gormt/data/view/model/model.go:46 +0xc39
github.com/xxjwxc/gormt/data/view/model.(*_Model).generate(0xc000565cd0, 0xc00016a092, 0x5)
	/Users/Django/www/tools/gormt/data/view/model/model.go:29 +0x1fa
github.com/xxjwxc/gormt/data/view/model.Generate(...)
	/Users/Django/www/tools/gormt/data/view/model/model.go:19
github.com/xxjwxc/gormt/data/view/gtools.Execute()
	/Users/Django/www/tools/gormt/data/view/gtools/gtools.go:25 +0x148
github.com/xxjwxc/gormt/data/cmd.glob..func1(0x1a285c0, 0x1a6ce10, 0x0, 0x0)
	/Users/Django/www/tools/gormt/data/cmd/cmd.go:27 +0x20
github.com/spf13/cobra.(*Command).execute(0x1a285c0, 0xc000094010, 0x0, 0x0, 0x1a285c0, 0xc000094010)
	/Users/Django/www/GOPATH/pkg/mod/github.com/spf13/[email protected]/command.go:830 +0x2aa
github.com/spf13/cobra.(*Command).ExecuteC(0x1a285c0, 0x0, 0x0, 0x0)
	/Users/Django/www/GOPATH/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/Django/www/GOPATH/pkg/mod/github.com/spf13/[email protected]/command.go:864
github.com/xxjwxc/gormt/data/cmd.Execute()
	/Users/Django/www/tools/gormt/data/cmd/cmd.go:35 +0x2d
main.main()
	/Users/Django/www/tools/gormt/main.go:6 +0x20

修改配置报错

λ gormt.exe -H=127.0.0.1 -d=base_document_queue -p=123456 -u=zrd --port=3306 -F=true
2020/08/25 14:26:55 using database info:
2020/08/25 14:26:55 {
     "Host": "127.0.0.1",
     "Port": 3306,
     "Username": "zrd",
     "Password": "123456",
     "Database": "base_document_queue"
}
panic: type (bit(10)) not match in any way.maybe need to add on (https://github.com/xxjwxc/gormt/blob/master/data/view/cnf/def.go)

关于SDK

请问作者有考虑做成SDK模式吗, 方便集成到自己程序里

tinyint(4)

panic: type (tinyint(4)) not match in any way.

"undefined: tools.GetJsonStr" when install gromt by go get

go: github.com/xxjwxc/gormt upgrade => v1.1.2
go: google.golang.org/appengine upgrade => v1.6.6
go: github.com/leodido/go-urn upgrade => v1.2.0
go: github.com/gookit/color upgrade => v1.2.5
go: github.com/spf13/cobra upgrade => v1.0.0
go: github.com/go-playground/universal-translator upgrade => v0.17.0
go: github.com/spf13/pflag upgrade => v1.0.5
go: gopkg.in/go-playground/validator.v9 upgrade => v9.31.0
go: github.com/jinzhu/gorm upgrade => v1.9.14
go: github.com/go-playground/locales upgrade => v0.13.0
go: github.com/go-sql-driver/mysql upgrade => v1.5.0
go: github.com/xxjwxc/public upgrade => v0.0.0-20200621092001-382926a82a5f
go: github.com/BurntSushi/toml upgrade => v0.3.1
go: go.uber.org/zap upgrade => v1.15.0
go: github.com/pkg/errors upgrade => v0.9.1
go: go.uber.org/multierr upgrade => v1.5.0
go: go.uber.org/atomic upgrade => v1.6.0
# github.com/xxjwxc/gormt/data/cmd
go/pkg/mod/github.com/xxjwxc/[email protected]/data/cmd/cmd.go:73:15: undefined: tools.GetJsonStr

不支持数据库是空密码

error info: Key: 'MysqlDbInfo.Password' Error:Field validation for 'Password' failed on the 'required' tag Key: 'MysqlDbInfo.Password' Error:Field validation for 'Password' failed on the 'required' tag

execute fail

panic: type (tinyint(2)) not match in any way.

can not parse cmd flags

./gormt -H=127.0.0.1 --port=3306 -d=db_order -p=Jd8fW -u=root -o=models -s=true

Can't read cmd: using (-h, --help) to get more imfo
error info: Key: 'MysqlDbInfo.Port' Error:Field validation for 'Port' failed on the 'required' tag Key: 'MysqlDbInfo.Port' Error:Field validation for 'Port' failed on the 'required' tag

当表名为order或者match时,无法生成对应的struct

以下为程序生成的日志:
(/Users/jianghongchao/Downloads/gormt-master/data/view/model/genmysql/genmysql.go:113) [2020-04-30 15:59:20] [Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match' at line 1]
goroutine 18 [running]:
runtime/debug.Stack(0xc0000119a0, 0xc0002ac6c0, 0x116)
/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/xxjwxc/public/mylog.SaveError(0xc0002ac480, 0x114, 0x160aa2a, 0x3)
/Users/jianghongchao/go/pkg/mod/github.com/xxjwxc/[email protected]/mylog/mylog.go:100 +0x382
github.com/xxjwxc/public/mysqldb.DbLog.Print(0x0, 0x0, 0xc000380a80, 0x3, 0x3)
/Users/jianghongchao/go/pkg/mod/github.com/xxjwxc/[email protected]/mysqldb/log.go:36 +0x99
github.com/jinzhu/gorm.(*DB).print(0xc0003b40d0, 0xc000380a80, 0x3, 0x3)
/Users/jianghongchao/go/pkg/mod/github.com/jinzhu/[email protected]/main.go:841 +0x52
created by github.com/jinzhu/gorm.(*DB).AddError
/Users/jianghongchao/go/pkg/mod/github.com/jinzhu/[email protected]/main.go:781 +0x2fc

数据表主键为id,序列化为jason时,不能输出主键?

type User struct {
ID int gorm:"primary_key;column:id;type:int(10) unsigned;not null" json:"-" // ID
Account string gorm:"column:account;type:varchar(255);not null" json:"account" // 账号
}

===============
如上,为什么" json:"-"` // ID,这样的话该结构序列化时,无法生成该字段,怎么解决?

有计划生成数据库表中现有数据的插入语句吗

有时候数据库中有些初始数据在程序初始化的时候需要导入,问一下作者有没有计划做对旧数据库表中现有数据生成导入新数据库表中的代码功能。

再次感谢作者提供这么好用的功能

this is my question,what should i do

goroutine 1 [running]:
github.com/xxjwxc/gormt/data/view/model.getTypeName(0xc0003fc790, 0x8, 0x1560455, 0x1)
/Users/apple/go/src/github.com/xxjwxc/gormt/data/view/model/common.go:47 +0x218
github.com/xxjwxc/gormt/data/view/model.(_Model).genTableElement(0xc000555cf8, 0xc00047a000, 0x14, 0x27, 0xc00014a700, 0x7, 0x8)
/Users/apple/go/src/github.com/xxjwxc/gormt/data/view/model/model.go:46 +0xc44
github.com/xxjwxc/gormt/data/view/model.(
_Model).generate(0xc000555cf8, 0x7ffeefbffab8, 0x6)
/Users/apple/go/src/github.com/xxjwxc/gormt/data/view/model/model.go:29 +0x1f9
github.com/xxjwxc/gormt/data/view/model.Generate(...)
/Users/apple/go/src/github.com/xxjwxc/gormt/data/view/model/model.go:19
github.com/xxjwxc/gormt/data/view/gtools.Execute()
/Users/apple/go/src/github.com/xxjwxc/gormt/data/view/gtools/gtools.go:25 +0x14a
github.com/xxjwxc/gormt/data/cmd.glob..func1(0x1a41e60, 0xc00033e420, 0x0, 0x6)
/Users/apple/go/src/github.com/xxjwxc/gormt/data/cmd/cmd.go:27 +0x20
github.com/spf13/cobra.(*Command).execute(0x1a41e60, 0xc0000b0010, 0x6, 0x6, 0x1a41e60, 0xc0000b0010)

GetByOption/GetByOptions系列函数功能无效

win10环境下,在gin这个web server下引入gormt生成的代码,调用方式跟测试案例类似,即:
userMgr := model.UserMgr(db)
userMgr.GetByOption(userMgr.WithAccount("aa"), userMgr.WithPwd("bb"))
发觉返回数据不正确,经调试,发觉GetByOption函数内部,调用apply的时候,拿不到传入进去的参数"aa"和"bb",调试查看变量的时候,提示报错 error code 299—— Only part of a ReadProcessMemory or WriteProcessMemory request was completed。而且最终得到的options.options这个map里存在Account和Pwd的key,但是里面的内容都是"",不知道具体是什么原因。

无法生成json tag

工具很好用,但是遇见个问题
如果下图配置,始终生成不了json tag,是我配置有问题吗?
image
image

how to use

大神,你这个文档写的看完也不知道怎么用,我的理解是:1.配置好yml 2.go build根目录下的main.go 但是貌似会编译失败 提示:go: github.com/go-playground/[email protected]: Get https://proxy.golang.org/github.com/go-playground/universal-translator/@v/v0.17.0.mod: dial tcp [2404:6800:4008:803::2011]:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. 求大神回复指导下

Cannot get latest version: module contains a go.mod file, so module path should be github.com/xxjwxc/gormt/v3

Background

The github.com/xxjwxc/gormt uses Go modules and the current release version is v3. And it’s module path is "github.com/xxjwxc/gormt", instead of "github.com/xxjwxc/gormt/v3". It must comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation. Quoting the specification:

A package that has opted in to modules must include the major version in the import path to import any v2+ modules
To preserve import compatibility, the go command requires that modules with major version v2 or later use a module path with that major version as the final element. For example, version v2.0.0 of example.com/m must instead use module path example.com/m/v2.
https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher

Steps to Reproduce

GO111MODULE=on, run go get targeting any version >= v2.0.0 of the xxjwxc/gormt:

$ go get github.com/xxjwxc/[email protected]
go: finding github.com/xxjwxc/gormt v3.0.6
go: finding github.com/xxjwxc/gormt v3.0.6
go get github.com/xxjwxc/[email protected]: github.com/xxjwxc/[email protected]: invalid version: module contains a go.mod file, so major version must be compatible: should be v0 or v1, not v3

run go get github.com/xxjwxc/gormt, the version will stuck in v1.1.2:

$go get github.com/xxjwxc/gormt
go: downloading github.com/xxjwxc/gormt v1.1.2
go: github.com/xxjwxc/gormt upgrade => v1.1.2 

SO anyone using Go modules will not be able to easily use any newer version of xxjwxc/gormt.

Solution

1. Kill the go.mod files, rolling back to GOPATH.

This would push them back to not being managed by Go modules (instead of incorrectly using Go modules).
Ensure compatibility for downstream module-aware projects and module-unaware projects projects

2. Fix module path to strictly follow SIV rules.

Patch the go.mod file to declare the module path as github.com/xxjwxc/gormt/v3 as per the specs. And adjust all internal imports.
The downstream projects might be negatively affected in their building if they are module-unaware (Go versions older than 1.9.7 and 1.10.3; Or use third-party dependency management tools, such as: Dep, glide,govendor…).

If you don't want to break the above repos. This method can provides better backwards-compatibility.
Release a v2 or higher module through the major subdirectory strategy: Create a new v3 subdirectory (github.com/xxjwxc/gormt/v3) and place a new go.mod file in that subdirectory. The module path must end with /v3. Copy or move the code into the v3 subdirectory. Update import statements within the module to also use /v3 (import "github.com/xxjwxc/gormt/v3/…"). Tag the release with v3.x.y.

3. Suggest your downstream module users use hash instead of a version tag.

If the standard rule of go modules conflicts with your development mode. Or not intended to be used as a library and does not make any guarantees about the API. So you can’t comply with the specification of "Releasing Modules for v2 or higher" available in the Modules documentation.
Regardless, since it's against one of the design choices of Go, it'll be a bit of a hack. Instead of go get github.com/xxjwxc/gormt@version-tag, module users need to use this following way to get the xxjwxc/gormt:
(1) Search for the tag you want (in browser)
(2) Get the commit hash for the tag you want
(3) Run go get github.com/xxjwxc/gormt@commit-hash
(4) Edit the go.mod file to put a comment about which version you actually used
This will make it difficult for module users to get and upgrade xxjwxc/gormt.

[*] You can see who will be affected here: [5 module users, e.g., weblazy/orm, psychopurp/Finders-Server, olongfen/note]
https://github.com/search?q=%22github.com%2Fxxjwxc%2Fgormt%22+filename%3Ago.mod&type=Code

Summary

You can make a choice to fix DM issues by balancing your own development schedules/mode against the affects on the downstream projects.

For this issue, Solution 2 can maximize your benefits and with minimal impacts to your downstream projects the ecosystem.

References

数据表主键为id,序列化为jason时,不能输出主键?

type User struct {
ID int gorm:"primary_key;column:id;type:int(10) unsigned;not null" json:"-" // ID
Account string gorm:"column:account;type:varchar(255);not null" json:"account" // 账号
}

===============
如上,为什么" json:"-"` // ID,这样的话该结构序列化时,无法生成该字段,怎么解决?

type (float unsigned) not match in any way.maybe need to add on

panic: type (float unsigned) not match in any way.maybe need to add on (https://github.com/xxjwxc/gormt/blob/master/data/view/cnf/def.go)

goroutine 1 [running]:
github.com/xxjwxc/gormt/data/view/model.getTypeName(0xc0003b8ee0, 0xe, 0x15e4806, 0x1)
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/view/model/common.go:61 +0x218
github.com/xxjwxc/gormt/data/view/model.(*_Model).genTableElement(0xc0002edc78, 0xc000191800, 0xb, 0x11, 0xc00039e380, 0x8, 0x8)
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/view/model/model.go:83 +0xcff
github.com/xxjwxc/gormt/data/view/model.(*_Model).GetPackage(0xc0002edc78, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/view/model/model.go:55 +0x25c
github.com/xxjwxc/gormt/data/view/model.(*_Model).generate(0xc0002edc78, 0xcea, 0xc0001b9158)
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/view/model/model.go:67 +0x3e
github.com/xxjwxc/gormt/data/view/model.Generate(0xc0001b9198, 0x8, 0xc0001b8e5a, 0x6, 0xc000300000, 0x46, 0x87, 0x87, 0x0, 0x1602672, ...)
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/view/model/model.go:31 +0xc3
github.com/xxjwxc/gormt/data/view/gtools.showCmd()
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/view/gtools/gtools.go:37 +0xb7
github.com/xxjwxc/gormt/data/view/gtools.Execute()
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/view/gtools/gtools.go:22 +0x38
github.com/xxjwxc/gormt/data/cmd.glob..func1(0x1b1ba60, 0x1b6f408, 0x0, 0x0)
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/cmd/cmd.go:32 +0x20
github.com/spf13/cobra.(*Command).execute(0x1b1ba60, 0xc00001e1b0, 0x0, 0x0, 0x1b1ba60, 0xc00001e1b0)
        /Users/xxj/work/path/pkg/mod/github.com/spf13/[email protected]/command.go:830 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0x1b1ba60, 0x0, 0x0, 0x0)
        /Users/xxj/work/path/pkg/mod/github.com/spf13/[email protected]/command.go:914 +0x2fb
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/xxj/work/path/pkg/mod/github.com/spf13/[email protected]/command.go:864
github.com/xxjwxc/gormt/data/cmd.Execute()
        /Users/xxj/work/workspace/github/xxjwxc/gormt/data/cmd/cmd.go:40 +0x2d
main.main()
        /Users/xxj/work/workspace/github/xxjwxc/gormt/main.go:6 +0x20

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.