master
jager 10 months ago
parent 3dea08f1e4
commit 5266255f35

1
.gitignore vendored

@ -7,3 +7,4 @@ db/oauth_db.go
gormt.yml
gormt
/vendor
.DS_Store

@ -1,4 +1,4 @@
all: # 构建
makeall: # 构建
make tar
windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o gormt.exe main.go

@ -1,46 +1,32 @@
base:
is_dev : false
out_dir : ./model # 输出目录
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
language : # 语言(English,中 文)
db_tag : gorm # 数据库标签名(gorm,db)
simple : true # 简单输出(默认只输出gorm主键和字段标签)
user_gorm_model : false # model是否使用gorm.Model
is_db_tag : true # 是否输出 数据库标签(gorm,db)
is_out_sql : false # 是否输出 sql 原信息
is_out_func : true # 是否输出 快捷函数
is_web_tag : true # 是否打web标记(json标记前提条件)
is_web_tag_pk_hidden: true # web标记是否隐藏主键
is_foreign_key : true # 是否导出外键关联
is_gui : false # 是否ui模式显示
is_table_name : true # 是否直接生成表名
is_column_name : true # 是否直接生成列名
is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
is_null_to_sql_null: false # 数据库默认 'DEFAULT NULL' 时设置结构为sql.NULL is_null_to_point如果为true则is_null_to_sql_null不生效
table_prefix : "" # 表前缀, 如果有则使用, 没有留空(如果表前缀以"-"开头则表示去掉该前缀struct、文件名都会去掉该前缀)
table_names: "" # 指定表生成,多个表用,隔开
is_out_file_by_table_name: false # 是否根据表名生成多个model
is_out_page: true # 是否输出分页函数
is_dev: false
out_dir: . # 输出目录
url_tag: json # web url tag(json,db(https://github.com/google/go-querystring))
is_web_tag: true # 是否打web标记(json标记前提条件)
language: 中文 # 语言(English,中文)
db_tag: gorm # 数据库标签(gorm,db)
simple: false # 简单输出(默认gorm标签不输出)
user_gorm_model: true # model是否使用gorm.Model
is_out_sql: false # 是否输出 sql 原信息
is_out_func: false # 是否输出 快捷函数
is_foreign_key: false # 是否导出外键关联
is_gui: false # 是否ui模式显示
is_table_name: true # 是否直接生成表名,列名
is_null_to_point: false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
is_web_tag_pk_hidden: false
table_prefix: "" #表前缀
table_names: "jc_payment_withdraw" #指定表生成,多个表用,隔开
is_column_name: true # 是否生成列名
is_out_file_by_table_name: true # 是否根据表名生成多个model
db_info:
host : 127.0.0.1 # type=1的时候host为yml文件全路径
port : 3306
username : root
password : 123456
database : matrix
host: 127.0.0.1
port: 3306
username: root
password: "joint.jager.168"
database: "game_center"
type: 0 # 数据库类型:0:mysql , 1:sqlite , 2:mssql
self_type_define: # 自定义数据类型映射
datetime: time.Time
time: time.Time
^(int)[(]\d+[)]: int
date: time.Time
out_file_name: "" # 自定义生成文件名
web_tag_type: 0 # json tag类型 0: 小驼峰 1: 下划线
# sqlite
# db_info:
# host : /Users/xxj/Downloads/caoguo # type=1的时候host为yml文件全路径
# port :
# username :
# password :
# database :
# type: 1 # 数据库类型:0:mysql , 1:sqlite , 2:mssql
web_tag_type: 1 # json tag类型 0: 小驼峰 1: 下划线

@ -81,12 +81,12 @@ func GetOutDir() string {
return _map.OutDir
}
// // SetSingularTable Set Disabled Table Name Plurals.设置禁用表名复数
// // SetSingularTable Set Disabled Table ChainType Plurals.设置禁用表名复数
// func SetSingularTable(b bool) {
// _map.SingularTable = b
// }
// // GetSingularTable Get Disabled Table Name Plurals.获取禁用表名复数
// // GetSingularTable Get Disabled Table ChainType Plurals.获取禁用表名复数
// func GetSingularTable() bool {
// return _map.SingularTable
// }
@ -275,7 +275,7 @@ func GetWebTagType() int {
return _map.WebTagType
}
//GetTableNames get format tableNames by config. 获取格式化后设置的表名
// GetTableNames get format tableNames by config. 获取格式化后设置的表名
func GetTableNames() string {
var sb strings.Builder
if _map.TableNames != "" {
@ -302,27 +302,27 @@ func GetTableNames() string {
return sb.String()
}
//GetOriginTableNames get origin tableNames. 获取原始的设置的表名
// GetOriginTableNames get origin tableNames. 获取原始的设置的表名
func GetOriginTableNames() string {
return _map.TableNames
}
//SetTableNames set tableNames. 设置生成的表名
// SetTableNames set tableNames. 设置生成的表名
func SetTableNames(tableNames string) {
_map.TableNames = tableNames
}
//GetIsColumnName get gen columnName config . 获取生成列名的config
// GetIsColumnName get gen columnName config . 获取生成列名的config
func GetIsColumnName() bool {
return _map.IsColumnName
}
//SetIsColumnName set gen ColumnName config. 设置生成列名的config
// SetIsColumnName set gen ColumnName config. 设置生成列名的config
func SetIsColumnName(isColumnName bool) {
_map.IsColumnName = isColumnName
}
//GetIsOutFileByTableName get gen columnName config . 设置是否根据表名生成文件
// GetIsOutFileByTableName get gen columnName config . 设置是否根据表名生成文件
func GetIsOutFileByTableName() bool {
return _map.IsOutFileByTableName
}

@ -7,7 +7,7 @@ import (
"github.com/jroimartin/gocui"
"github.com/xxjwxc/gormt/data/view/model"
"github.com/xxjwxc/gormt/data/view/model/genmysql"
"github.com/xxjwxc/gormt/data/view/model/gensqlite"
//"github.com/xxjwxc/gormt/data/view/model/gensqlite"
"github.com/xxjwxc/gormt/data/config"
@ -79,8 +79,8 @@ func generate(g *gocui.Gui, v *gocui.View) {
switch config.GetDbInfo().Type {
case 0:
modeldb = genmysql.GetModel()
case 1:
modeldb = gensqlite.GetModel()
//case 1:
// modeldb = gensqlite.GetModel()
}
if modeldb == nil {
mylog.Error(fmt.Errorf("modeldb not fund : please check db_info.type (0:mysql , 1:sqlite , 2:mssql) "))

@ -8,6 +8,32 @@ func (m *{{.StructName}}) TableName() string {
}
`
genColumn = `
type I{{.StructName}} interface {
{{range $em := .Em}}
Get{{$em.StructName}}() {{$em.Type}}{{end}}
}
{{$module := .StructName}}
{{range $em := .Em}}
func (m *{{$module}}) Get{{$em.StructName}}() {{$em.Type}} {
return m.{{$em.StructName}}
}
{{end}}
// ToMap struct to map 结构体转成map
func (m *{{.StructName}}) ToMap() map[string]any {
return map[string]any{ {{range $em := .Em}}
"{{$em.ColumnName}}":m.{{$em.StructName}}, {{end}}
}
}
// ToMapWithoutModel struct to map 结构体转成map, 不带gorm.Model
func (m *{{.StructName}}) ToMapWithoutModel() map[string]any {
return map[string]any{ {{range $em := .Em}} {{ if and (ne $em.ColumnName "id") (ne $em.ColumnName "created_at") (ne $em.ColumnName "updated_at") (ne $em.ColumnName "deleted_at") }}
"{{$em.ColumnName}}":m.{{$em.StructName}}, {{end}}{{end}}
}
}
// {{.StructName}}Columns get sql column name.获取数据库列名
var {{.StructName}}Columns = struct { {{range $em := .Em}}
{{$em.StructName}} string{{end}}

@ -160,6 +160,7 @@ func (s *GenStruct) GenerateColumnName() []string {
Em []struct {
ColumnName string
StructName string
Type string
}
}
data.StructName = s.Name
@ -168,18 +169,21 @@ func (s *GenStruct) GenerateColumnName() []string {
data.Em = append(data.Em, []struct {
ColumnName string
StructName string
Type string
}{
{ColumnName: "id", StructName: "ID"},
{ColumnName: "created_at", StructName: "CreatedAt"},
{ColumnName: "updated_at", StructName: "UpdatedAt"},
{ColumnName: "deleted_at", StructName: "DeletedAt"},
{ColumnName: "id", StructName: "ID", Type: "uint"},
{ColumnName: "created_at", StructName: "CreatedAt", Type: "time.Time"},
{ColumnName: "updated_at", StructName: "UpdatedAt", Type: "time.Time"},
{ColumnName: "deleted_at", StructName: "DeletedAt", Type: "gorm.DeletedAt"},
}...)
} else if len(v.ColumnName) > 0 {
data.Em = append(data.Em, struct {
ColumnName string
StructName string
Type string
}{ColumnName: v.ColumnName,
StructName: v.Name,
Type: v.Type,
})
}
@ -260,7 +264,7 @@ func (p *GenPackage) AddStruct(st GenStruct) {
// Generate Get the result data.获取结果数据
func (p *GenPackage) Generate() string {
p.genimport() // auto add import .补充 import
p.AddImport(`"time"`)
var pa generate.PrintAtom
pa.Add("package", p.Name)
// add import

@ -2,7 +2,7 @@ package genstruct
// GenElement element of sturct.元素类
type GenElement struct {
Name string // Name.元素名
Name string // ChainType.元素名
ColumnName string // table name.表名
Type string // Type.类型标记
Notes string // Notes.注释

@ -11,9 +11,9 @@ import (
"github.com/xxjwxc/gormt/data/config"
"github.com/xxjwxc/gormt/data/view/model/genmssql"
//"github.com/xxjwxc/gormt/data/view/model/genmssql"
"github.com/xxjwxc/gormt/data/view/model/genmysql"
"github.com/xxjwxc/gormt/data/view/model/gensqlite"
//"github.com/xxjwxc/gormt/data/view/model/gensqlite"
"github.com/xxjwxc/public/tools"
)
@ -35,10 +35,10 @@ func showCmd() {
switch config.GetDbInfo().Type {
case 0: // mysql
modeldb = genmysql.GetModel()
case 1: // sqllite
modeldb = gensqlite.GetModel()
case 2: //
modeldb = genmssql.GetModel()
//case 1: // sqllite
// modeldb = gensqlite.GetModel()
//case 2: //
// modeldb = genmssql.GetModel()
}
if modeldb == nil {
mylog.Error(fmt.Errorf("modeldb not fund : please check db_info.type (0:mysql , 1:sqlite , 2:mssql) "))

File diff suppressed because one or more lines are too long

@ -1,100 +0,0 @@
package genmssql
import (
"strings"
"github.com/xxjwxc/gormt/data/config"
"github.com/xxjwxc/public/mylog"
"github.com/xxjwxc/gormt/data/view/model"
)
// filterModel filter.过滤 gorm.Model
func filterModel(list *[]genColumns) bool {
if config.GetDBTag() != "gorm" || !config.GetUserGormModel() {
return false
}
var _temp []genColumns
num := 0
for _, v := range *list {
if strings.EqualFold(v.Field, "id") ||
strings.EqualFold(v.Field, "created_at") ||
strings.EqualFold(v.Field, "updated_at") ||
strings.EqualFold(v.Field, "deleted_at") {
num++
} else {
_temp = append(_temp, v)
}
}
if num >= 4 {
*list = _temp
return true
}
return false
}
// fixForeignKey fix foreign key.过滤外键
func fixForeignKey(list []genForeignKey, columuName string, result *[]model.ForeignKey) {
for _, v := range list {
if strings.EqualFold(v.ColumnName, columuName) { // find it .找到了
*result = append(*result, model.ForeignKey{
TableName: v.ReferencedTableName,
ColumnName: v.ReferencedColumnName,
})
}
}
}
// GetModel get model interface. 获取model接口
func GetModel() model.IModel {
//now just support mysql
return &MssqlModel
}
// FixNotes 分析元素表注释
func FixNotes(em *model.ColumnsInfo, note string) {
b0 := FixElementTag(em, note) // gorm
b1 := FixForeignKeyTag(em, em.Notes) // 外键
if !b0 && b1 { // 补偿
FixElementTag(em, em.Notes) // gorm
}
}
// FixElementTag 分析元素表注释
func FixElementTag(em *model.ColumnsInfo, note string) bool {
matches := noteRegex.FindStringSubmatch(note)
if len(matches) < 2 {
em.Notes = note
return false
}
mylog.Infof("get one gorm tag:(%v) ==> (%v)", em.BaseInfo.Name, matches[1])
em.Notes = note[len(matches[0]):]
em.Gormt = matches[1]
return true
}
// FixForeignKeyTag 分析元素表注释(外键)
func FixForeignKeyTag(em *model.ColumnsInfo, note string) bool {
matches := foreignKeyRegex.FindStringSubmatch(note) // foreign key 外键
if len(matches) < 2 {
em.Notes = note
return false
}
em.Notes = note[len(matches[0]):]
// foreign key 外键
tmp := strings.Split(matches[1], ".")
if len(tmp) > 0 {
mylog.Infof("get one foreign key:(%v) ==> (%v)", em.BaseInfo.Name, matches[1])
em.ForeignKeyList = append(em.ForeignKeyList, model.ForeignKey{
TableName: tmp[0],
ColumnName: tmp[1],
})
}
return true
}

@ -1,46 +0,0 @@
package genmssql
import "regexp"
// genColumns show full columns
type genColumns struct {
Field string `gorm:"column:Field"`
Type string `gorm:"column:Type"`
Key string `gorm:"column:Key"`
Desc string `gorm:"column:Comment"`
Null string `gorm:"column:Null"`
Default *string `gorm:"column:Default"`
}
//select table_schema,table_name,column_name,referenced_table_schema,referenced_table_name,referenced_column_name from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
// where table_schema ='matrix' AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = 'credit_card' ;
// genForeignKey Foreign key of db info . 表的外键信息
type genForeignKey struct {
TableSchema string `gorm:"column:table_schema"` // Database of columns.列所在的数据库
TableName string `gorm:"column:table_name"` // Data table of column.列所在的数据表
ColumnName string `gorm:"column:column_name"` // Column names.列名
ReferencedTableSchema string `gorm:"column:referenced_table_schema"` // The database where the index is located.该索引所在的数据库
ReferencedTableName string `gorm:"column:referenced_table_name"` // Affected tables . 该索引受影响的表
ReferencedColumnName string `gorm:"column:referenced_column_name"` // Which column of the affected table.该索引受影响的表的哪一列
}
/////////////////////////////////////////////////////////////////////////
// TableDescription 表及表注释
type TableDescription struct {
Name string `gorm:"column:name"` // 表名
Value string `gorm:"column:value"` // 表注释
}
type ColumnKeys struct {
ID int `gorm:"column:id"`
Name string `gorm:"column:name"` // 列名
Pk int `gorm:"column:pk"` // 是否主键
Type string `gorm:"column:tp"` // 类型
Length int `gorm:"column:len"` // 长度
Isnull int `gorm:"column:isnull"` // 是否为空
Desc string `gorm:"column:des"` // 列注释
}
var noteRegex = regexp.MustCompile(`^\[@gorm\s(\S+)+\]`)
var foreignKeyRegex = regexp.MustCompile(`^\[@fk\s(\S+)+\]`)

@ -1,257 +0,0 @@
package genmssql
import (
"fmt"
"sort"
"strings"
"github.com/xxjwxc/gormt/data/config"
"github.com/xxjwxc/gormt/data/view/model"
"github.com/xxjwxc/public/mylog"
"github.com/xxjwxc/public/tools"
"gorm.io/driver/sqlserver"
"gorm.io/gorm"
)
// MssqlModel mysql model from IModel
var MssqlModel mssqlModel
type mssqlModel struct {
}
// GenModel get model.DBInfo info.获取数据库相关属性
func (m *mssqlModel) GenModel() model.DBInfo {
dsn := fmt.Sprintf("server=%v;database=%v;user id=%v;password=%v;port=%v;encrypt=disable",
config.GetDbInfo().Host, config.GetDbInfo().Database, config.GetDbInfo().Username, config.GetDbInfo().Password, config.GetDbInfo().Port)
db, err := gorm.Open(sqlserver.Open(dsn), &gorm.Config{})
if err != nil {
mylog.Error(err)
return model.DBInfo{}
}
defer func() {
sqldb, _ := db.DB()
sqldb.Close()
}()
var dbInfo model.DBInfo
m.getPackageInfo(db, &dbInfo)
dbInfo.PackageName = m.GetPkgName()
dbInfo.DbName = m.GetDbName()
return dbInfo
}
// GetDbName get database name.获取数据库名字
func (m *mssqlModel) GetDbName() string {
return config.GetDbInfo().Database
}
// GetTableNames get table name.获取格式化后指定的表名
func (m *mssqlModel) GetTableNames() string {
return config.GetTableNames()
}
// GetOriginTableNames get table name.获取原始指定的表名
func (m *mssqlModel) GetOriginTableNames() string {
return config.GetOriginTableNames()
}
// GetPkgName package names through config outdir configuration.通过config outdir 配置获取包名
func (m *mssqlModel) GetPkgName() string {
dir := config.GetOutDir()
dir = strings.Replace(dir, "\\", "/", -1)
if len(dir) > 0 {
if dir[len(dir)-1] == '/' {
dir = dir[:(len(dir) - 1)]
}
}
var pkgName string
list := strings.Split(dir, "/")
if len(list) > 0 {
pkgName = list[len(list)-1]
}
if len(pkgName) == 0 || pkgName == "." {
list = strings.Split(tools.GetModelPath(), "/")
if len(list) > 0 {
pkgName = list[len(list)-1]
}
}
return pkgName
}
func (m *mssqlModel) getPackageInfo(orm *gorm.DB, info *model.DBInfo) {
tabls := m.getTables(orm) // get table and notes
// if m := config.GetTableList(); len(m) > 0 {
// // 制定了表之后
// newTabls := make(map[string]string)
// for t := range m {
// if notes, ok := tabls[t]; ok {
// newTabls[t] = notes
// } else {
// fmt.Printf("table: %s not found in db\n", t)
// }
// }
// tabls = newTabls
// }
for tabName, notes := range tabls {
var tab model.TabInfo
tab.Name = tabName
tab.Notes = notes
if config.GetIsOutSQL() {
// TODO:获取创建sql语句
// Get create SQL statements.获取创建sql语句
// rows, err := orm.Raw("show create table " + assemblyTable(tabName)).Rows()
// //defer rows.Close()
// if err == nil {
// if rows.Next() {
// var table, CreateTable string
// rows.Scan(&table, &CreateTable)
// tab.SQLBuildStr = CreateTable
// }
// }
// rows.Close()
// ----------end
}
// build element.构造元素
tab.Em = m.getTableElement(orm, tabName)
// --------end
info.TabList = append(info.TabList, tab)
}
// sort tables
sort.Slice(info.TabList, func(i, j int) bool {
return info.TabList[i].Name < info.TabList[j].Name
})
}
// getTableElement Get table columns and comments.获取表列及注释
func (m *mssqlModel) getTableElement(orm *gorm.DB, tab string) (el []model.ColumnsInfo) {
sql := fmt.Sprintf(`SELECT
id = a.colorder,
name = a.name,
pk = case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then 1 else 0 end,
tp = b.name,
len = COLUMNPROPERTY(a.id,a.name,'PRECISION'),
isnull = a.isnullable,
des = isnull(g.[value],'')
FROM
syscolumns a
left join
systypes b
on
a.xusertype=b.xusertype
inner join
sysobjects d
on
a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join
sys.extended_properties g
on
a.id=G.major_id and a.colid=g.minor_id
left join
sys.extended_properties f
on
d.id=f.major_id and f.minor_id=0
where
d.name='%v'
order by
a.colorder`, tab)
lenPk := 0
// get keys
var Keys []ColumnKeys
orm.Raw(sql).Scan(&Keys)
for i := 0; i < len(Keys); i++ {
v := &Keys[i]
if v.Pk == 1 {
lenPk++
}
if strings.EqualFold(v.Type, "varchar") { // 字符串
v.Type = fmt.Sprintf("varchar(%v)", v.Length)
} else if strings.EqualFold(v.Type, "int") { // int
v.Type = fmt.Sprintf("int(%v)", v.Length)
}
}
// ----------end
// TODO:ForeignKey
for _, v := range Keys {
var tmp model.ColumnsInfo
tmp.Name = v.Name
tmp.Type = v.Type
FixNotes(&tmp, v.Desc) // 分析表注释
if v.Pk > 0 { // 主键,或者联合组件
if lenPk <= 1 { // 主键
tmp.Index = append(tmp.Index, model.KList{
Key: model.ColumnsKeyPrimary,
Multi: false,
KeyType: "primaryKey",
})
} else {
tmp.Index = append(tmp.Index, model.KList{
Key: model.ColumnsKeyPrimary,
Multi: true,
KeyType: "FULLTEXT",
})
}
}
tmp.IsNull = (v.Isnull == 1)
el = append(el, tmp)
}
return
}
// getTables Get columns and comments.获取表列及注释
func (m *mssqlModel) getTables(orm *gorm.DB) map[string]string {
tbDesc := make(map[string]string)
// Get column names.获取列名
if m.GetOriginTableNames() != "" {
sarr := strings.Split(m.GetOriginTableNames(), ",")
if len(sarr) != 0 {
for _, val := range sarr {
tbDesc[val] = ""
}
}
} else {
var list []TableDescription
err := orm.Raw(`SELECT DISTINCT
d.name,
f.value
FROM
syscolumns a
LEFT JOIN systypes b ON a.xusertype= b.xusertype
INNER JOIN sysobjects d ON a.id= d.id
AND d.xtype= 'U'
AND d.name<> 'dtproperties'
LEFT JOIN syscomments e ON a.cdefault= e.id
LEFT JOIN sys.extended_properties g ON a.id= G.major_id
AND a.colid= g.minor_id
LEFT JOIN sys.extended_properties f ON d.id= f.major_id
AND f.minor_id= 0 ;`).Scan(&list).Error
if err != nil {
if !config.GetIsGUI() {
fmt.Println(err)
}
return tbDesc
}
for _, v := range list {
tbDesc[v.Name] = v.Value
}
}
return tbDesc
}
func assemblyTable(name string) string {
return "`" + name + "`"
}

@ -1,96 +0,0 @@
package gensqlite
import (
"strings"
"github.com/xxjwxc/gormt/data/config"
"github.com/xxjwxc/gormt/data/view/model"
)
// filterModel filter.过滤 gorm.Model
func filterModel(list *[]genColumns) bool {
if config.GetDBTag() != "gorm" || !config.GetUserGormModel() {
return false
}
var _temp []genColumns
num := 0
for _, v := range *list {
if strings.EqualFold(v.Name, "id") ||
strings.EqualFold(v.Name, "created_at") ||
strings.EqualFold(v.Name, "updated_at") ||
strings.EqualFold(v.Name, "deleted_at") {
num++
} else {
_temp = append(_temp, v)
}
}
if num >= 4 {
*list = _temp
return true
}
return false
}
// fixForeignKey fix foreign key.过滤外键
func fixForeignKey(list []genForeignKey, columuName string, result *[]model.ForeignKey) {
for _, v := range list {
if strings.EqualFold(v.ColumnName, columuName) { // find it .找到了
*result = append(*result, model.ForeignKey{
TableName: v.ReferencedTableName,
ColumnName: v.ReferencedColumnName,
})
}
}
}
// GetModel get model interface. 获取model接口
func GetModel() model.IModel {
//now just support mysql
return &SQLiteModel
}
// FixNotes 分析元素表注释
func FixNotes(em *model.ColumnsInfo, note string) {
b0 := FixElementTag(em, note) // gorm
b1 := FixForeignKeyTag(em, em.Notes) // 外键
if !b0 && b1 { // 补偿
FixElementTag(em, em.Notes) // gorm
}
}
// FixElementTag 分析元素表注释
func FixElementTag(em *model.ColumnsInfo, note string) bool {
matches := noteRegex.FindStringSubmatch(note)
if len(matches) < 2 {
em.Notes = note
return false
}
em.Notes = note[len(matches[0]):]
em.Gormt = matches[1]
return true
}
// FixForeignKeyTag 分析元素表注释(外键)
func FixForeignKeyTag(em *model.ColumnsInfo, note string) bool {
matches := foreignKeyRegex.FindStringSubmatch(note) // foreign key 外键
if len(matches) < 2 {
em.Notes = note
return false
}
em.Notes = note[len(matches[0]):]
// foreign key 外键
tmp := strings.Split(matches[1], ".")
if len(tmp) > 0 {
em.ForeignKeyList = append(em.ForeignKeyList, model.ForeignKey{
TableName: tmp[0],
ColumnName: tmp[1],
})
}
return true
}

@ -1,32 +0,0 @@
package gensqlite
import "regexp"
type keys struct {
NonUnique int `gorm:"column:Non_unique"`
KeyName string `gorm:"column:Key_name"`
ColumnName string `gorm:"column:Column_name"`
}
// genColumns show full columns
type genColumns struct {
Name string `gorm:"column:name"`
Type string `gorm:"column:type"`
Pk int `gorm:"column:pk"`
NotNull int `gorm:"column:notnull"`
}
//select table_schema,table_name,column_name,referenced_table_schema,referenced_table_name,referenced_column_name from INFORMATION_SCHEMA.KEY_COLUMN_USAGE
// where table_schema ='matrix' AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = 'credit_card' ;
// genForeignKey Foreign key of db info . 表的外键信息
type genForeignKey struct {
TableSchema string `gorm:"column:table_schema"` // Database of columns.列所在的数据库
TableName string `gorm:"column:table_name"` // Data table of column.列所在的数据表
ColumnName string `gorm:"column:column_name"` // Column names.列名
ReferencedTableSchema string `gorm:"column:referenced_table_schema"` // The database where the index is located.该索引所在的数据库
ReferencedTableName string `gorm:"column:referenced_table_name"` // Affected tables . 该索引受影响的表
ReferencedColumnName string `gorm:"column:referenced_column_name"` // Which column of the affected table.该索引受影响的表的哪一列
}
var noteRegex = regexp.MustCompile(`^\[@gorm\s(\S+)+\]`)
var foreignKeyRegex = regexp.MustCompile(`^\[@fk\s(\S+)+\]`)

@ -1,205 +0,0 @@
package gensqlite
import (
"fmt"
"sort"
"strings"
"github.com/xxjwxc/public/mylog"
"github.com/xxjwxc/gormt/data/config"
"github.com/xxjwxc/gormt/data/view/model"
"github.com/xxjwxc/public/tools"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
// SQLiteModel mysql model from IModel
var SQLiteModel sqliteModel
type sqliteModel struct {
}
// GenModel get model.DBInfo info.获取数据库相关属性
func (m *sqliteModel) GenModel() model.DBInfo {
db, err := gorm.Open(sqlite.Open(config.GetDbInfo().Host), &gorm.Config{})
if err != nil {
mylog.Error(err)
return model.DBInfo{}
}
defer func() {
sqldb, _ := db.DB()
sqldb.Close()
}()
var dbInfo model.DBInfo
m.getPackageInfo(db, &dbInfo)
dbInfo.PackageName = m.GetPkgName()
dbInfo.DbName = m.GetDbName()
return dbInfo
}
// GetDbName get database name.获取数据库名字
func (m *sqliteModel) GetDbName() string {
dir := config.GetDbInfo().Host
dir = strings.Replace(dir, "\\", "/", -1)
if len(dir) > 0 {
if dir[len(dir)-1] == '/' {
dir = dir[:(len(dir) - 1)]
}
}
var dbName string
list := strings.Split(dir, "/")
if len(list) > 0 {
dbName = list[len(list)-1]
}
list = strings.Split(dbName, ".")
if len(list) > 0 {
dbName = list[0]
}
if len(dbName) == 0 || dbName == "." {
panic(fmt.Sprintf("%v : db host config err.must file dir", dbName))
}
return dbName
}
// GetTableNames get table name.获取指定的表名
func (m *sqliteModel) GetTableNames() string {
return config.GetTableNames()
}
// GetPkgName package names through config outdir configuration.通过config outdir 配置获取包名
func (m *sqliteModel) GetPkgName() string {
dir := config.GetOutDir()
dir = strings.Replace(dir, "\\", "/", -1)
if len(dir) > 0 {
if dir[len(dir)-1] == '/' {
dir = dir[:(len(dir) - 1)]
}
}
var pkgName string
list := strings.Split(dir, "/")
if len(list) > 0 {
pkgName = list[len(list)-1]
}
if len(pkgName) == 0 || pkgName == "." {
list = strings.Split(tools.GetModelPath(), "/")
if len(list) > 0 {
pkgName = list[len(list)-1]
}
}
return pkgName
}
func (m *sqliteModel) getPackageInfo(orm *gorm.DB, info *model.DBInfo) {
tabls := m.getTables(orm) // get table and notes
for tabName, notes := range tabls {
var tab model.TabInfo
tab.Name = tabName
tab.Notes = notes
if config.GetIsOutSQL() {
// Get create SQL statements.获取创建sql语句
rows, err := orm.Raw("SELECT tbl_name,sql FROM sqlite_master WHERE type='table' AND name = " + assemblyTable(tabName)).Rows()
//defer rows.Close()
if err == nil {
if rows.Next() {
var table, CreateTable string
rows.Scan(&table, &CreateTable)
tab.SQLBuildStr = CreateTable
}
}
rows.Close()
// ----------end
}
// build element.构造元素
tab.Em = m.getTableElement(orm, tabName)
// --------end
info.TabList = append(info.TabList, tab)
}
// sort tables
sort.Slice(info.TabList, func(i, j int) bool {
return info.TabList[i].Name < info.TabList[j].Name
})
}
// getTableElement Get table columns and comments.获取表列及注释
func (m *sqliteModel) getTableElement(orm *gorm.DB, tab string) (el []model.ColumnsInfo) {
var list []genColumns
// Get table annotations.获取表注释
orm.Raw(fmt.Sprintf("PRAGMA table_info(%v)", assemblyTable(tab))).Scan(&list)
// filter gorm.Model.过滤 gorm.Model
if filterModel(&list) {
el = append(el, model.ColumnsInfo{
Type: "gorm.Model",
})
}
// -----------------end
// ForeignKey
var foreignKeyList []genForeignKey
if config.GetIsForeignKey() {
}
// ------------------end
for _, v := range list {
var tmp model.ColumnsInfo
tmp.Name = v.Name
tmp.Type = v.Type
FixNotes(&tmp, "")
if v.Pk == 1 { // 主键
tmp.Index = append(tmp.Index, model.KList{
Key: model.ColumnsKeyPrimary,
Multi: false,
})
}
tmp.IsNull = (v.NotNull != 1)
// ForeignKey
fixForeignKey(foreignKeyList, tmp.Name, &tmp.ForeignKeyList)
// -----------------end
el = append(el, tmp)
}
return
}
// getTables Get columns and comments.获取表列及注释
func (m *sqliteModel) getTables(orm *gorm.DB) map[string]string {
tbDesc := make(map[string]string)
// Get column names.获取列名
var tables []string
rows, err := orm.Raw("SELECT name FROM sqlite_master WHERE type='table'").Rows()
if err != nil {
if !config.GetIsGUI() {
fmt.Println(err)
}
return tbDesc
}
for rows.Next() {
var table string
rows.Scan(&table)
if !strings.EqualFold(table, "sqlite_sequence") { // 剔除系统默认
tables = append(tables, table)
tbDesc[table] = ""
}
}
rows.Close()
// TODO.获取表注释
return tbDesc
}
func assemblyTable(name string) string {
return "'" + name + "'"
}

File diff suppressed because one or more lines are too long

@ -14,9 +14,7 @@ require (
gopkg.in/go-playground/validator.v9 v9.30.2
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
gorm.io/driver/mysql v1.0.1
gorm.io/driver/sqlite v1.1.4
gorm.io/driver/sqlserver v1.0.7
gorm.io/gorm v1.21.4
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55
)
// replace github.com/xxjwxc/public => ../public

@ -31,8 +31,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/denisenkom/go-mssqldb v0.9.0 h1:RSohk2RsiZqLZ0zCjtfn3S4Gp4exhpBWHyQ7D0yGjAk=
github.com/denisenkom/go-mssqldb v0.9.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
@ -58,7 +56,6 @@ github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@ -99,8 +96,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jroimartin/gocui v0.4.0 h1:52jnalstgmc25FmtGcWqa0tcbMEWS6RpFLsOIO+I+E8=
github.com/jroimartin/gocui v0.4.0/go.mod h1:7i7bbj99OgFHzo7kB2zPb8pXLqMBSQegY7azfqXMkyY=
@ -123,8 +120,6 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
@ -208,8 +203,6 @@ golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@ -228,7 +221,6 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -249,8 +241,6 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
@ -305,14 +295,9 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.0.1 h1:omJoilUzyrAp0xNoio88lGJCroGdIOen9hq2A/+3ifw=
gorm.io/driver/mysql v1.0.1/go.mod h1:KtqSthtg55lFp3S5kUXqlGaelnWpKitn4k1xZTnoiPw=
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
gorm.io/driver/sqlserver v1.0.7 h1:uwUtb0kdFwW5PkRbd2KJ2h4wlsqvLSjox1XVg/RnzRE=
gorm.io/driver/sqlserver v1.0.7/go.mod h1:ng66aHI47ZIKz/vvnxzDoonzmTS8HXP+JYlgg67wOog=
gorm.io/gorm v1.9.19/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.20.2/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.21.4 h1:J0xfPJMRfHgpVcYLrEAIqY/apdvTIkrltPQNHQLq9Qc=
gorm.io/gorm v1.21.4/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55 h1:sC1Xj4TYrLqg1n3AN10w871An7wJM0gzgcm8jkIkECQ=
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

BIN
image/.DS_Store vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 81 KiB

Before

Width:  |  Height:  |  Size: 242 KiB

After

Width:  |  Height:  |  Size: 242 KiB

Before

Width:  |  Height:  |  Size: 250 KiB

After

Width:  |  Height:  |  Size: 250 KiB

Before

Width:  |  Height:  |  Size: 618 KiB

After

Width:  |  Height:  |  Size: 618 KiB

Before

Width:  |  Height:  |  Size: 952 KiB

After

Width:  |  Height:  |  Size: 952 KiB

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

@ -0,0 +1,311 @@
package gormt
import (
"time"
)
// JcPaymentWithdraw 用户提币订单表
type JcPaymentWithdraw struct {
ID uint64 `gorm:"autoIncrement:true;primaryKey;column:id;type:bigint unsigned;not null;comment:'主键ID'" json:"id"` // 主键ID
InvoiceCode string `gorm:"unique;column:invoice_code;type:varchar(64);not null;default:'';comment:'发票编码'" json:"invoice_code"` // 发票编码
AppID string `gorm:"column:app_id;type:varchar(64);not null;default:'';comment:'应用ID'" json:"app_id"` // 应用ID
OrderID string `gorm:"column:order_id;type:varchar(64);not null;default:'';comment:'游戏端订单ID'" json:"order_id"` // 游戏端订单ID
UserID string `gorm:"index:user_id;column:user_id;type:varchar(64);not null;default:'';comment:'用户游戏ID'" json:"user_id"` // 用户游戏ID
UserType int8 `gorm:"column:user_type;type:tinyint;not null;default:0;comment:'用户类型0-玩家1-商家2-其他'" json:"user_type"` // 用户类型0-玩家1-商家2-其他
FromAddress string `gorm:"column:from_address;type:varchar(64);not null;default:'';comment:'发币账号地址'" json:"from_address"` // 发币账号地址
ToAddress string `gorm:"column:to_address;type:varchar(64);not null;default:'';comment:'用户提币地址'" json:"to_address"` // 用户提币地址
ChainNet string `gorm:"index:chain_net;column:chain_net;type:varchar(16);not null;default:'';comment:'网络类型, options:BTC|ERC20|BEP20|TRC20'" json:"chain_net"` // 网络类型, options:BTC|ERC20|BEP20|TRC20
Token string `gorm:"index:token;column:token;type:varchar(16);not null;default:'';comment:'代币, options:BTC|USDT|ETH|BNB|TRX|USDP|USDC'" json:"token"` // 代币, options:BTC|USDT|ETH|BNB|TRX|USDP|USDC
AmountInput float64 `gorm:"column:amount_input;type:decimal(40,18);not null;default:0.000000000000000000;comment:'用户输入的提币金额'" json:"amount_input"` // 用户输入的提币金额
AmountCredited float64 `gorm:"column:amount_credited;type:decimal(40,18);not null;default:0.000000000000000000;comment:'实际到账金额'" json:"amount_credited"` // 实际到账金额
GasToken float64 `gorm:"column:gas_token;type:decimal(40,18);not null;default:0.000000000000000000;comment:'手续费换算对应token 扣掉的, 基于gas_limit计算'" json:"gas_token"` // 手续费换算对应token 扣掉的, 基于gas_limit计算
GasRate float64 `gorm:"column:gas_rate;type:decimal(40,18);not null;default:0.000000000000000000;comment:'燃料费(基础币)兑token的汇率'" json:"gas_rate"` // 燃料费(基础币)兑token的汇率
UserFeeRate float64 `gorm:"column:user_fee_rate;type:decimal(40,18);not null;default:0.000000000000000000;comment:'扣除玩家手续费的倍率,从配置文件中取'" json:"user_fee_rate"` // 扣除玩家手续费的倍率,从配置文件中取
GasLimit float64 `gorm:"column:gas_limit;type:decimal(40,18);not null;default:0.000000000000000000;comment:'提币的燃料费限制'" json:"gas_limit"` // 提币的燃料费限制
GasPrice float64 `gorm:"column:gas_price;type:decimal(40,18);not null;default:0.000000000000000000;comment:'燃料费价格,用于计算需要花费的基础币'" json:"gas_price"` // 燃料费价格,用于计算需要花费的基础币
GasFee float64 `gorm:"column:gas_fee;type:decimal(40,18);not null;default:0.000000000000000000;comment:'实际转账燃料费'" json:"gas_fee"` // 实际转账燃料费
SendCount int `gorm:"column:send_count;type:int;not null;comment:'广播交易次数'" json:"send_count"` // 广播交易次数
SendAt time.Time `gorm:"column:send_at;type:timestamp;default:null;comment:'发送交易时间'" json:"send_at"` // 发送交易时间
SendRemark string `gorm:"column:send_remark;type:varchar(255);not null;default:'';comment:'交易出错备注'" json:"send_remark"` // 交易出错备注
CheckTimes int `gorm:"column:check_times;type:int;not null;default:0;comment:'查询结果次数'" json:"check_times"` // 查询结果次数
CheckRemark string `gorm:"column:check_remark;type:varchar(255);not null;default:'';comment:'检查出错备注'" json:"check_remark"` // 检查出错备注
SuccessAt time.Time `gorm:"column:success_at;type:timestamp;default:null;comment:'成功的时间'" json:"success_at"` // 成功的时间
TxHash string `gorm:"index:tx_hash;column:tx_hash;type:varchar(80);not null;default:'';comment:'交易哈希'" json:"tx_hash"` // 交易哈希
Status int8 `gorm:"column:status;type:tinyint;not null;default:0;comment:'订单状态:0待转账,1转账中,2发送成功待确认,3确认成功,4确认失败,5已退款,6已关闭'" json:"status"` // 订单状态:0待转账,1转账中,2发送成功待确认,3确认成功,4确认失败,5已退款,6已关闭
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;comment:'创建时间'" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;not null;default:CURRENT_TIMESTAMP;comment:'更新时间'" json:"updated_at"` // 更新时间
}
// TableName get sql table name.获取数据库表名
func (m *JcPaymentWithdraw) TableName() string {
return "jc_payment_withdraw"
}
type IJcPaymentWithdraw interface {
GetID() uint64
GetInvoiceCode() string
GetAppID() string
GetOrderID() string
GetUserID() string
GetUserType() int8
GetFromAddress() string
GetToAddress() string
GetChainNet() string
GetToken() string
GetAmountInput() float64
GetAmountCredited() float64
GetGasToken() float64
GetGasRate() float64
GetUserFeeRate() float64
GetGasLimit() float64
GetGasPrice() float64
GetGasFee() float64
GetSendCount() int
GetSendAt() time.Time
GetSendRemark() string
GetCheckTimes() int
GetCheckRemark() string
GetSuccessAt() time.Time
GetTxHash() string
GetStatus() int8
GetCreatedAt() time.Time
GetUpdatedAt() time.Time
}
func (m *JcPaymentWithdraw) GetID() uint64 {
return m.ID
}
func (m *JcPaymentWithdraw) GetInvoiceCode() string {
return m.InvoiceCode
}
func (m *JcPaymentWithdraw) GetAppID() string {
return m.AppID
}
func (m *JcPaymentWithdraw) GetOrderID() string {
return m.OrderID
}
func (m *JcPaymentWithdraw) GetUserID() string {
return m.UserID
}
func (m *JcPaymentWithdraw) GetUserType() int8 {
return m.UserType
}
func (m *JcPaymentWithdraw) GetFromAddress() string {
return m.FromAddress
}
func (m *JcPaymentWithdraw) GetToAddress() string {
return m.ToAddress
}
func (m *JcPaymentWithdraw) GetChainNet() string {
return m.ChainNet
}
func (m *JcPaymentWithdraw) GetToken() string {
return m.Token
}
func (m *JcPaymentWithdraw) GetAmountInput() float64 {
return m.AmountInput
}
func (m *JcPaymentWithdraw) GetAmountCredited() float64 {
return m.AmountCredited
}
func (m *JcPaymentWithdraw) GetGasToken() float64 {
return m.GasToken
}
func (m *JcPaymentWithdraw) GetGasRate() float64 {
return m.GasRate
}
func (m *JcPaymentWithdraw) GetUserFeeRate() float64 {
return m.UserFeeRate
}
func (m *JcPaymentWithdraw) GetGasLimit() float64 {
return m.GasLimit
}
func (m *JcPaymentWithdraw) GetGasPrice() float64 {
return m.GasPrice
}
func (m *JcPaymentWithdraw) GetGasFee() float64 {
return m.GasFee
}
func (m *JcPaymentWithdraw) GetSendCount() int {
return m.SendCount
}
func (m *JcPaymentWithdraw) GetSendAt() time.Time {
return m.SendAt
}
func (m *JcPaymentWithdraw) GetSendRemark() string {
return m.SendRemark
}
func (m *JcPaymentWithdraw) GetCheckTimes() int {
return m.CheckTimes
}
func (m *JcPaymentWithdraw) GetCheckRemark() string {
return m.CheckRemark
}
func (m *JcPaymentWithdraw) GetSuccessAt() time.Time {
return m.SuccessAt
}
func (m *JcPaymentWithdraw) GetTxHash() string {
return m.TxHash
}
func (m *JcPaymentWithdraw) GetStatus() int8 {
return m.Status
}
func (m *JcPaymentWithdraw) GetCreatedAt() time.Time {
return m.CreatedAt
}
func (m *JcPaymentWithdraw) GetUpdatedAt() time.Time {
return m.UpdatedAt
}
// ToMap struct to map 结构体转成map
func (m *JcPaymentWithdraw) ToMap() map[string]any {
return map[string]any{
"id": m.ID,
"invoice_code": m.InvoiceCode,
"app_id": m.AppID,
"order_id": m.OrderID,
"user_id": m.UserID,
"user_type": m.UserType,
"from_address": m.FromAddress,
"to_address": m.ToAddress,
"chain_net": m.ChainNet,
"token": m.Token,
"amount_input": m.AmountInput,
"amount_credited": m.AmountCredited,
"gas_token": m.GasToken,
"gas_rate": m.GasRate,
"user_fee_rate": m.UserFeeRate,
"gas_limit": m.GasLimit,
"gas_price": m.GasPrice,
"gas_fee": m.GasFee,
"send_count": m.SendCount,
"send_at": m.SendAt,
"send_remark": m.SendRemark,
"check_times": m.CheckTimes,
"check_remark": m.CheckRemark,
"success_at": m.SuccessAt,
"tx_hash": m.TxHash,
"status": m.Status,
"created_at": m.CreatedAt,
"updated_at": m.UpdatedAt,
}
}
// ToMapWithoutModel struct to map 结构体转成map, 不带gorm.Model
func (m *JcPaymentWithdraw) ToMapWithoutModel() map[string]any {
return map[string]any{
"invoice_code": m.InvoiceCode,
"app_id": m.AppID,
"order_id": m.OrderID,
"user_id": m.UserID,
"user_type": m.UserType,
"from_address": m.FromAddress,
"to_address": m.ToAddress,
"chain_net": m.ChainNet,
"token": m.Token,
"amount_input": m.AmountInput,
"amount_credited": m.AmountCredited,
"gas_token": m.GasToken,
"gas_rate": m.GasRate,
"user_fee_rate": m.UserFeeRate,
"gas_limit": m.GasLimit,
"gas_price": m.GasPrice,
"gas_fee": m.GasFee,
"send_count": m.SendCount,
"send_at": m.SendAt,
"send_remark": m.SendRemark,
"check_times": m.CheckTimes,
"check_remark": m.CheckRemark,
"success_at": m.SuccessAt,
"tx_hash": m.TxHash,
"status": m.Status,
}
}
// JcPaymentWithdrawColumns get sql column name.获取数据库列名
var JcPaymentWithdrawColumns = struct {
ID string
InvoiceCode string
AppID string
OrderID string
UserID string
UserType string
FromAddress string
ToAddress string
ChainNet string
Token string
AmountInput string
AmountCredited string
GasToken string
GasRate string
UserFeeRate string
GasLimit string
GasPrice string
GasFee string
SendCount string
SendAt string
SendRemark string
CheckTimes string
CheckRemark string
SuccessAt string
TxHash string
Status string
CreatedAt string
UpdatedAt string
}{
ID: "id",
InvoiceCode: "invoice_code",
AppID: "app_id",
OrderID: "order_id",
UserID: "user_id",
UserType: "user_type",
FromAddress: "from_address",
ToAddress: "to_address",
ChainNet: "chain_net",
Token: "token",
AmountInput: "amount_input",
AmountCredited: "amount_credited",
GasToken: "gas_token",
GasRate: "gas_rate",
UserFeeRate: "user_fee_rate",
GasLimit: "gas_limit",
GasPrice: "gas_price",
GasFee: "gas_fee",
SendCount: "send_count",
SendAt: "send_at",
SendRemark: "send_remark",
CheckTimes: "check_times",
CheckRemark: "check_remark",
SuccessAt: "success_at",
TxHash: "tx_hash",
Status: "status",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}

File diff suppressed because one or more lines are too long

@ -0,0 +1,31 @@
package gormt
import (
"time"
)
// Prompt [...]
type Prompt struct {
}
// TableName get sql table name.获取数据库表名
func (m *Prompt) TableName() string {
return "prompt"
}
type IPrompt interface {
}
// ToMap struct to map 结构体转成map
func (m *Prompt) ToMap() map[string]any {
return map[string]any{}
}
// ToMapWithoutModel struct to map 结构体转成map, 不带gorm.Model
func (m *Prompt) ToMapWithoutModel() map[string]any {
return map[string]any{}
}
// PromptColumns get sql column name.获取数据库列名
var PromptColumns = struct {
}{}
Loading…
Cancel
Save