mirror of
https://github.com/go-home-admin/toolset.git
synced 2025-12-24 13:37:52 +08:00
feat: 表关联
This commit is contained in:
@@ -74,7 +74,6 @@ func GenMysql(name string, conf Conf, out string) {
|
||||
str += baseFunStr
|
||||
str += genFieldFunc(table, columns)
|
||||
str += genListFunc(table, columns)
|
||||
str += genWithFunc(table, columns, conf)
|
||||
err := os.WriteFile(file+"_gen.go", []byte(str), 0766)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -110,36 +109,6 @@ func genListFunc(table string, columns []tableColumn) string {
|
||||
return str
|
||||
}
|
||||
|
||||
func genWithFunc(table string, columns []tableColumn, conf Conf) string {
|
||||
TableName := parser.StringToHump(table)
|
||||
str := ""
|
||||
if helper, ok := conf["helper"]; ok {
|
||||
helperConf := helper.(map[interface{}]interface{})
|
||||
tableConfig, ok := helperConf[table].([]interface{})
|
||||
if ok {
|
||||
for _, c := range tableConfig {
|
||||
cf := c.(map[interface{}]interface{})
|
||||
with := cf["with"]
|
||||
tbName := parser.StringToHump(cf["table"].(string))
|
||||
switch with {
|
||||
case "many2many":
|
||||
|
||||
default:
|
||||
str += "\nfunc (orm *Orm" + TableName + ") Joins" + tbName + "(args ...interface{}) *Orm" + TableName + " {" +
|
||||
"\n\torm.db.Joins(\"" + cf["alias"].(string) + "\", args...)" +
|
||||
"\n\treturn orm" +
|
||||
"\n}"
|
||||
str += "\nfunc (orm *Orm" + TableName + ") Preload" + tbName + "(args ...interface{}) *Orm" + TableName + " {" +
|
||||
"\n\torm.db.Preload(\"" + cf["alias"].(string) + "\", args...)" +
|
||||
"\n\treturn orm" +
|
||||
"\n}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func genFieldFunc(table string, columns []tableColumn) string {
|
||||
TableName := parser.StringToHump(table)
|
||||
|
||||
|
||||
@@ -64,7 +64,6 @@ func GenSql(name string, conf Conf, out string) {
|
||||
str += baseFunStr
|
||||
str += genFieldFunc(table, columns)
|
||||
str += genListFunc(table, columns)
|
||||
str += genWithFunc(table, columns, conf)
|
||||
err := os.WriteFile(file+"_gen.go", []byte(str), 0766)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -100,36 +99,6 @@ func genListFunc(table string, columns []tableColumn) string {
|
||||
return str
|
||||
}
|
||||
|
||||
func genWithFunc(table string, columns []tableColumn, conf Conf) string {
|
||||
TableName := parser.StringToHump(table)
|
||||
str := ""
|
||||
if helper, ok := conf["helper"]; ok {
|
||||
helperConf := helper.(map[interface{}]interface{})
|
||||
tableConfig, ok := helperConf[table].([]interface{})
|
||||
if ok {
|
||||
for _, c := range tableConfig {
|
||||
cf := c.(map[interface{}]interface{})
|
||||
with := cf["with"]
|
||||
tbName := parser.StringToHump(cf["table"].(string))
|
||||
switch with {
|
||||
case "many2many":
|
||||
|
||||
default:
|
||||
str += "\nfunc (orm *Orm" + TableName + ") Joins" + tbName + "(args ...interface{}) *Orm" + TableName + " {" +
|
||||
"\n\torm.db.Joins(\"" + cf["alias"].(string) + "\", args...)" +
|
||||
"\n\treturn orm" +
|
||||
"\n}"
|
||||
str += "\nfunc (orm *Orm" + TableName + ") Preload" + tbName + "(args ...interface{}) *Orm" + TableName + " {" +
|
||||
"\n\torm.db.Preload(\"" + cf["alias"].(string) + "\", args...)" +
|
||||
"\n\treturn orm" +
|
||||
"\n}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func genFieldFunc(table string, columns []tableColumn) string {
|
||||
TableName := parser.StringToHump(table)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user