feat: 表关联

This commit is contained in:
aliang
2022-10-26 15:41:27 +08:00
parent 94fde7f7d3
commit 2990f54c7d
2 changed files with 0 additions and 62 deletions

View File

@@ -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)

View File

@@ -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)