Skip to content

Commit

Permalink
fix: 仅主键才生成InsertGetXX的辅助函数
Browse files Browse the repository at this point in the history
  • Loading branch information
zodial committed Jun 16, 2023
1 parent 329a19b commit 081a0cf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions console/commands/orm/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ func genFieldFunc(table string, columns []tableColumn) string {
goType = "*" + goType
}
// if 主键, 生成In, > <
str += "\nfunc (orm *Orm" + TableName + ") InsertGet" + column.ColumnName + "(row *" + TableName + ") " + goType + " {" +
"\n\torm.db.Create(row)" +
"\n\treturn row." + column.ColumnName +
"\n}"
if column.COLUMN_KEY == "PRI" {
str += "\nfunc (orm *Orm" + TableName + ") InsertGet" + column.ColumnName + "(row *" + TableName + ") " + goType + " {" +
"\n\torm.db.Create(row)" +
"\n\treturn row." + column.ColumnName +
"\n}"
}

str += "\nfunc (orm *Orm" + TableName + ") Where" + column.ColumnName + "In(val []" + column.GoType + ") *Orm" + TableName + " {" +
"\n\torm.db.Where(\"`" + column.COLUMN_NAME + "` IN ?\", val)" +
Expand Down

0 comments on commit 081a0cf

Please sign in to comment.