Skip to content

Commit

Permalink
feat: 表关联
Browse files Browse the repository at this point in the history
  • Loading branch information
zodial committed Oct 26, 2022
1 parent 94fde7f commit 2990f54
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 62 deletions.
31 changes: 0 additions & 31 deletions console/commands/orm/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
31 changes: 0 additions & 31 deletions console/commands/pgorm/pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 2990f54

Please sign in to comment.