foreign key en
This commit is contained in:
160
README.md
160
README.md
@@ -37,6 +37,7 @@ Usage:
|
||||
|
||||
Flags:
|
||||
-d, --database string 数据库名
|
||||
-f, --foreign 是否导出外键关联
|
||||
-h, --help help for main
|
||||
-H, --host string 数据库地址.(注意-H为大写)
|
||||
-o, --outdir string 输出目录
|
||||
@@ -56,17 +57,58 @@ Flags:
|
||||
- Database tables, column field annotation support
|
||||
- singular_table, Table name plural (big Camel-Case)
|
||||
- json tag json tag output
|
||||
- gorm.Model
|
||||
- gorm.Model [Support export gorm.model>>>](doc/export_cn.md)
|
||||
- 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>>>](doc/export_cn.md)
|
||||
|
||||
### You can enrich data types in [def](https://github.com/xxjwxc/gormt/blob/master/data/view/gtools/def.go)
|
||||
### You can enrich data types in [def](data/view/cnf/def.go)
|
||||
|
||||
## 5. Demonstration
|
||||
|
||||
## 5. build
|
||||
- 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. build
|
||||
```
|
||||
make windows
|
||||
make linux
|
||||
@@ -78,115 +120,11 @@ or
|
||||
go generate
|
||||
```
|
||||
|
||||
## 6. Demonstration
|
||||
## 7. Next step
|
||||
|
||||
- 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_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`),
|
||||
UNIQUE KEY `UNIQ_5696AD037D3656A4` (`app_key`,`user_info_id`) USING BTREE,
|
||||
KEY `user_info_id` (`user_info_id`),
|
||||
CONSTRAINT `1` FOREIGN KEY (`user_info_id`) REFERENCES `user_info_tbl` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户信息'
|
||||
```
|
||||
- param :singular_table = false simple = false
|
||||
- Add common function (ormfunc)
|
||||
|
||||
###### --->Derived results
|
||||
|
||||
```
|
||||
// User information
|
||||
type UserAccountTbl struct {
|
||||
ID int `gorm:"primary_key;column:id;type:int(11);not null" json:"-"` //
|
||||
Account string `gorm:"unique;column:account;type:varchar(64);not null" json:"account"` //
|
||||
Password string `gorm:"column:password;type:varchar(64);not null" json:"password"` //
|
||||
AccountType int `gorm:"column:account_type;type:int(11);not null" json:"account_type"` // 帐号类型:0手机号,1邮件
|
||||
AppKey string `json:"app_key" gorm:"unique_index:UNIQ_5696AD037D3656A4;column:app_key;type:varchar(255);not null"` // authbucket_oauth2_client表的id
|
||||
UserInfoID int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index;column:user_info_id;type:int(11);not null" json:"user_info_id"` //
|
||||
RegTime time.Time `gorm:"column:reg_time;type:datetime" json:"reg_time"` //
|
||||
RegIP string `gorm:"column:reg_ip;type:varchar(15)" json:"reg_ip"` //
|
||||
BundleID string `json:"bundle_id" gorm:"column:bundle_id;type:varchar(255)"` //
|
||||
Describ string `gorm:"column:describ;type:varchar(255)" json:"describ"` //
|
||||
}
|
||||
```
|
||||
|
||||
###### --->erived results
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
type UserAccountTbl struct {
|
||||
ID int `json:"-" gorm:"primary_key"` //
|
||||
Account string `gorm:"unique" json:"account"` //
|
||||
Password string `json:"password"` //
|
||||
AccountType int `json:"account_type"` // 帐号类型:0手机号,1邮件
|
||||
AppKey string `gorm:"unique_index:UNIQ_5696AD037D3656A4" json:"app_key"` // authbucket_oauth2_client表的id
|
||||
UserInfoID int `json:"user_info_id" gorm:"unique_index:UNIQ_5696AD037D3656A4;index"` //
|
||||
RegTime time.Time `json:"reg_time"` //
|
||||
RegIP string `json:"reg_ip"` //
|
||||
BundleID string `json:"bundle_id"` //
|
||||
Describ string `json:"describ"` //
|
||||
}
|
||||
```
|
||||
|
||||
- param :singular_table = false simple = true isJsonTag = false
|
||||
|
||||
###### --->erived results
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
type UserAccountTbl struct {
|
||||
ID int `gorm:"primary_key"` //
|
||||
Account string `gorm:"unique"` //
|
||||
Password string //
|
||||
AccountType int // 帐号类型:0手机号,1邮件
|
||||
AppKey string `gorm:"unique_index:UNIQ_5696AD037D3656A4"` // authbucket_oauth2_client表的id
|
||||
UserInfoID int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index"` //
|
||||
RegTime time.Time //
|
||||
RegIP string //
|
||||
BundleID string //
|
||||
Describ string //
|
||||
}
|
||||
```
|
||||
|
||||
- sql:
|
||||
```
|
||||
CREATE TABLE `user_info_tbl` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`nickname` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
`headurl` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`created_at` datetime DEFAULT NULL,
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
`deleted_at` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户信息'
|
||||
```
|
||||
|
||||
- param :singular_table = false simple = true isJsonTag = false
|
||||
|
||||
###### --->erived results
|
||||
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
type UserInfoTbl struct {
|
||||
gorm.Model //
|
||||
Nickname string //
|
||||
Headurl string //
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## 7. one windows gui tools
|
||||
## 8. one windows gui tools
|
||||
|
||||

|
||||
|
||||
@@ -198,8 +136,6 @@ type UserInfoTbl struct {
|
||||
|
||||
[Download](https://github.com/xxjwxc/gormt/releases/download/v1.1.0/v1.0.zip)
|
||||
|
||||
## 8. Next step
|
||||
|
||||
- support (ForeignKey)
|
||||
|
||||
- ###### [link](https://xxjwxc.github.io/post/gormtools/)
|
||||
|
||||
@@ -54,7 +54,7 @@ Flags:
|
||||
- 数据库表,列字段注释支持
|
||||
- singular_table 表名复数(大驼峰)
|
||||
- json tag json标签输出
|
||||
- gorm.Model 基本模型 [简单带外键模式导出>>>](doc/export_cn.md)
|
||||
- gorm.Model 基本模型 [支持gorm.Model模式导出>>>](doc/export_cn.md)
|
||||
- PRIMARY_KEY 将列指定为主键
|
||||
- UNIQUE 将列指定为唯一
|
||||
- NOT NULL 将列指定为非 NULL
|
||||
|
||||
@@ -58,7 +58,7 @@ func init() {
|
||||
rootCmd.MarkFlagRequired("singular")
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(&foreignKey, "foreign", "f", false, "是否导出外键关联")
|
||||
rootCmd.MarkFlagRequired("foreign")
|
||||
rootCmd.MarkFlagRequired("foreign key")
|
||||
|
||||
rootCmd.Flags().IntVar(&mysqlInfo.Port, "port", 3306, "端口号")
|
||||
}
|
||||
|
||||
200
doc/export.md
200
doc/export.md
@@ -1,4 +1,15 @@
|
||||
## 5. 导出
|
||||
## 目录
|
||||
- [sql code](#sql-code)
|
||||
- [Mult complex export without foreign key](#Mult-complex-export-without-foreign-key)
|
||||
- [Complex single table mode export](#Complex-single-table-mode-export)
|
||||
- [Simple export with JSON](#Simple-export-with-JSON)
|
||||
- [Simple export without JSON](#Simple-export-without-JSON)
|
||||
- [Simple with foreign key mode export](#Simple-with-foreign-key-mode-export)
|
||||
- [sql2](#sql2)
|
||||
- [Support export gorm.model](#Support export gorm.model)
|
||||
|
||||
|
||||
### sql code
|
||||
|
||||
- sql:
|
||||
```
|
||||
@@ -8,97 +19,143 @@ CREATE TABLE `user_account_tbl` (
|
||||
`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_id` int(11) NOT NULL,
|
||||
`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`),
|
||||
UNIQUE KEY `UNIQ_5696AD037D3656A4` (`app_key`,`user_info_id`) USING BTREE,
|
||||
KEY `user_info_id` (`user_info_id`),
|
||||
CONSTRAINT `1` FOREIGN KEY (`user_info_id`) REFERENCES `user_info_tbl` (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户信息'
|
||||
UNIQUE KEY `account` (`account`) USING BTREE,
|
||||
UNIQUE KEY `UNIQ_5696AD037D3656A4` (`app_key`,`user_info_tbl_id`) 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=27 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='用户账号'
|
||||
```
|
||||
- 参数:singular_table = false simple = false
|
||||
|
||||
###### --->导出结果
|
||||
-------------
|
||||
|
||||
### Mult complex export without foreign key
|
||||
|
||||
- param:singular_table = false simple = false is_foreign_key = false
|
||||
|
||||
###### --->export result
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
// UserAccountTbl 用户账号
|
||||
type UserAccountTbl struct {
|
||||
ID int `gorm:"primary_key;column:id;type:int(11);not null" json:"-"` //
|
||||
Account string `gorm:"unique;column:account;type:varchar(64);not null" json:"account"` //
|
||||
Password string `gorm:"column:password;type:varchar(64);not null" json:"password"` //
|
||||
AccountType int `gorm:"column:account_type;type:int(11);not null" json:"account_type"` // 帐号类型:0手机号,1邮件
|
||||
AppKey string `json:"app_key" gorm:"unique_index:UNIQ_5696AD037D3656A4;column:app_key;type:varchar(255);not null"` // authbucket_oauth2_client表的id
|
||||
UserInfoID int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index;column:user_info_id;type:int(11);not null" json:"user_info_id"` //
|
||||
RegTime time.Time `gorm:"column:reg_time;type:datetime" json:"reg_time"` //
|
||||
RegIP string `gorm:"column:reg_ip;type:varchar(15)" json:"reg_ip"` //
|
||||
BundleID string `json:"bundle_id" gorm:"column:bundle_id;type:varchar(255)"` //
|
||||
Describ string `gorm:"column:describ;type:varchar(255)" json:"describ"` //
|
||||
ID int `gorm:"primary_key;column:id;type:int(11);not null" json:"-"`
|
||||
Account string `gorm:"unique;column:account;type:varchar(64);not null" json:"account"`
|
||||
Password string `gorm:"column:password;type:varchar(64);not null" json:"password"`
|
||||
AccountType int `gorm:"column:account_type;type:int(11);not null" json:"account_type"` // 帐号类型:0手机号,1邮件
|
||||
AppKey string `gorm:"unique_index:UNIQ_5696AD037D3656A4;column:app_key;type:varchar(255);not null" json:"app_key"` // authbucket_oauth2_client表的id
|
||||
UserInfoTblID int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index;column:user_info_tbl_id;type:int(11);not null" json:"user_info_tbl_id"`
|
||||
RegTime time.Time `gorm:"column:reg_time;type:datetime" json:"reg_time"`
|
||||
RegIP string `gorm:"column:reg_ip;type:varchar(15)" json:"reg_ip"`
|
||||
BundleID string `gorm:"column:bundle_id;type:varchar(255)" json:"bundle_id"`
|
||||
Describ string `gorm:"column:describ;type:varchar(255)" json:"describ"`
|
||||
}
|
||||
```
|
||||
|
||||
- 参数:singular_table = true simple = false
|
||||
-------------
|
||||
|
||||
###### --->导出结果
|
||||
### Complex single table mode export
|
||||
|
||||
- param:singular_table = true simple = false is_foreign_key = false
|
||||
|
||||
###### --->export result
|
||||
|
||||
```
|
||||
// UserAccountTbl 用户账号
|
||||
type User_account_tbl struct {
|
||||
Id int `gorm:"primary_key;column:id;type:int(11);not null" json:"-"` //
|
||||
Account string `gorm:"unique;column:account;type:varchar(64);not null" json:"account"` //
|
||||
Password string `gorm:"column:password;type:varchar(64);not null" json:"password"` //
|
||||
Account_type int `gorm:"column:account_type;type:int(11);not null" json:"account_type"` // 帐号类型:0手机号,1邮件
|
||||
App_key string `gorm:"unique_index:UNIQ_5696AD037D3656A4;column:app_key;type:varchar(255);not null" json:"app_key"` // authbucket_oauth2_client表的id
|
||||
User_info_id int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index;column:user_info_id;type:int(11);not null" json:"user_info_id"` //
|
||||
Reg_time time.Time `gorm:"column:reg_time;type:datetime" json:"reg_time"` //
|
||||
Reg_ip string `gorm:"column:reg_ip;type:varchar(15)" json:"reg_ip"` //
|
||||
Bundle_id string `gorm:"column:bundle_id;type:varchar(255)" json:"bundle_id"` //
|
||||
Describ string `gorm:"column:describ;type:varchar(255)" json:"describ"` //
|
||||
Id int `gorm:"primary_key;column:id;type:int(11);not null" json:"-"`
|
||||
Account string `gorm:"unique;column:account;type:varchar(64);not null" json:"account"`
|
||||
Password string `gorm:"column:password;type:varchar(64);not null" json:"password"`
|
||||
Account_type int `gorm:"column:account_type;type:int(11);not null" json:"account_type"` // 帐号类型:0手机号,1邮件
|
||||
App_key string `gorm:"unique_index:UNIQ_5696AD037D3656A4;column:app_key;type:varchar(255);not null" json:"app_key"` // authbucket_oauth2_client表的id
|
||||
User_info_tbl_id int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index;column:user_info_tbl_id;type:int(11);not null" json:"user_info_tbl_id"`
|
||||
Reg_time time.Time `gorm:"column:reg_time;type:datetime" json:"reg_time"`
|
||||
Reg_ip string `gorm:"column:reg_ip;type:varchar(15)" json:"reg_ip"`
|
||||
Bundle_id string `gorm:"column:bundle_id;type:varchar(255)" json:"bundle_id"`
|
||||
Describ string `gorm:"column:describ;type:varchar(255)" json:"describ"`
|
||||
}
|
||||
```
|
||||
- 参数:singular_table = false simple = true isJsonTag = true
|
||||
|
||||
###### --->导出结果
|
||||
-------------
|
||||
|
||||
### Simple-export-with-JSON
|
||||
|
||||
- param:singular_table = false simple = true is_json_tag = true is_foreign_key = false
|
||||
|
||||
###### --->export result
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
// UserAccountTbl 用户账号
|
||||
type UserAccountTbl struct {
|
||||
ID int `json:"-" gorm:"primary_key"` //
|
||||
Account string `gorm:"unique" json:"account"` //
|
||||
Password string `json:"password"` //
|
||||
AccountType int `json:"account_type"` // 帐号类型:0手机号,1邮件
|
||||
AppKey string `gorm:"unique_index:UNIQ_5696AD037D3656A4" json:"app_key"` // authbucket_oauth2_client表的id
|
||||
UserInfoID int `json:"user_info_id" gorm:"unique_index:UNIQ_5696AD037D3656A4;index"` //
|
||||
RegTime time.Time `json:"reg_time"` //
|
||||
RegIP string `json:"reg_ip"` //
|
||||
BundleID string `json:"bundle_id"` //
|
||||
Describ string `json:"describ"` //
|
||||
ID int `gorm:"primary_key" json:"-"`
|
||||
Account string `gorm:"unique" json:"account"`
|
||||
Password string `json:"password"`
|
||||
AccountType int `json:"account_type"` // 帐号类型:0手机号,1邮件
|
||||
AppKey string `gorm:"unique_index:UNIQ_5696AD037D3656A4" json:"app_key"` // authbucket_oauth2_client表的id
|
||||
UserInfoTblID int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index" json:"user_info_tbl_id"`
|
||||
RegTime time.Time `json:"reg_time"`
|
||||
RegIP string `json:"reg_ip"`
|
||||
BundleID string `json:"bundle_id"`
|
||||
Describ string `json:"describ"`
|
||||
}
|
||||
```
|
||||
|
||||
- 参数:singular_table = false simple = true isJsonTag = false
|
||||
|
||||
###### --->导出结果
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
--------------
|
||||
|
||||
### Simple export without JSON
|
||||
|
||||
- param:singular_table = false simple = true is_json_tag = false is_foreign_key = false
|
||||
|
||||
###### --->export result
|
||||
|
||||
```
|
||||
// UserAccountTbl 用户账号
|
||||
type UserAccountTbl struct {
|
||||
ID int `gorm:"primary_key"` //
|
||||
Account string `gorm:"unique"` //
|
||||
Password string //
|
||||
AccountType int // 帐号类型:0手机号,1邮件
|
||||
AppKey string `gorm:"unique_index:UNIQ_5696AD037D3656A4"` // authbucket_oauth2_client表的id
|
||||
UserInfoID int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index"` //
|
||||
RegTime time.Time //
|
||||
RegIP string //
|
||||
BundleID string //
|
||||
Describ string //
|
||||
ID int `gorm:"primary_key"`
|
||||
Account string `gorm:"unique"`
|
||||
Password string
|
||||
AccountType int // 帐号类型:0手机号,1邮件
|
||||
AppKey string `gorm:"unique_index:UNIQ_5696AD037D3656A4"` // authbucket_oauth2_client表的id
|
||||
UserInfoTblID int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index"`
|
||||
RegTime time.Time
|
||||
RegIP string
|
||||
BundleID string
|
||||
Describ string
|
||||
}
|
||||
```
|
||||
|
||||
- sql:
|
||||
--------------
|
||||
|
||||
### Simple with foreign key mode export
|
||||
|
||||
- param:singular_table = false simple = true is_json_tag = false is_foreign_key = true
|
||||
|
||||
###### --->export result
|
||||
|
||||
```
|
||||
// UserAccountTbl 用户账号
|
||||
type UserAccountTbl struct {
|
||||
ID int `gorm:"primary_key"`
|
||||
Account string `gorm:"unique"`
|
||||
Password string
|
||||
AccountType int // 帐号类型:0手机号,1邮件
|
||||
AppKey string `gorm:"unique_index:UNIQ_5696AD037D3656A4"` // authbucket_oauth2_client表的id
|
||||
UserInfoTblID int `gorm:"unique_index:UNIQ_5696AD037D3656A4;index"`
|
||||
UserInfoTbl UserInfoTbl `gorm:"association_foreignkey:user_info_tbl_id;foreignkey:id"` // 用户信息
|
||||
RegTime time.Time
|
||||
RegIP string
|
||||
BundleID string
|
||||
Describ string
|
||||
}
|
||||
```
|
||||
|
||||
--------------
|
||||
|
||||
## sql2
|
||||
```
|
||||
CREATE TABLE `user_info_tbl` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
@@ -107,20 +164,23 @@ CREATE TABLE `user_info_tbl` (
|
||||
`created_at` datetime DEFAULT NULL,
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
`deleted_at` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='用户信息'
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `id` (`id`,`created_at`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='用户信息'
|
||||
```
|
||||
|
||||
- 参数:singular_table = false simple = true isJsonTag = false
|
||||
### Support export gorm.model
|
||||
|
||||
###### --->导出结果
|
||||
- param:singular_table = false simple = true is_json_tag = false
|
||||
|
||||
###### --->export result
|
||||
|
||||
|
||||
```
|
||||
// 用户信息
|
||||
// UserInfoTbl 用户信息
|
||||
type UserInfoTbl struct {
|
||||
gorm.Model //
|
||||
Nickname string //
|
||||
Headurl string //
|
||||
gorm.Model
|
||||
Nickname string
|
||||
Headurl string
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user