From 2990f54c7dc85a8d1640d50994dcca971a7dae11 Mon Sep 17 00:00:00 2001 From: aliang Date: Wed, 26 Oct 2022 15:41:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A8=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- console/commands/orm/mysql.go | 31 ------------------------------- console/commands/pgorm/pgsql.go | 31 ------------------------------- 2 files changed, 62 deletions(-) diff --git a/console/commands/orm/mysql.go b/console/commands/orm/mysql.go index 727f956..5df23e5 100644 --- a/console/commands/orm/mysql.go +++ b/console/commands/orm/mysql.go @@ -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) diff --git a/console/commands/pgorm/pgsql.go b/console/commands/pgorm/pgsql.go index db3b644..a93e02f 100644 --- a/console/commands/pgorm/pgsql.go +++ b/console/commands/pgorm/pgsql.go @@ -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)