2020-07-29 17:11:41 +08:00
|
|
|
package gen
|
|
|
|
|
|
|
|
import (
|
2020-08-19 10:41:19 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/model/sql/template"
|
2020-10-19 23:13:18 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
2020-07-29 17:11:41 +08:00
|
|
|
)
|
|
|
|
|
2020-08-19 10:41:19 +08:00
|
|
|
func genNew(table Table, withCache bool) (string, error) {
|
2020-10-21 14:59:35 +08:00
|
|
|
text, err := util.LoadTemplate(category, modelNewTemplateFile, template.New)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2020-10-19 23:13:18 +08:00
|
|
|
output, err := util.With("new").
|
2020-10-21 14:59:35 +08:00
|
|
|
Parse(text).
|
2020-08-19 10:41:19 +08:00
|
|
|
Execute(map[string]interface{}{
|
2020-12-21 09:43:32 +08:00
|
|
|
"table": wrapWithRawString(table.Name.Source()),
|
2020-08-19 10:41:19 +08:00
|
|
|
"withCache": withCache,
|
2020-08-20 10:29:18 +08:00
|
|
|
"upperStartCamelObject": table.Name.ToCamel(),
|
2020-08-19 10:41:19 +08:00
|
|
|
})
|
2020-07-29 17:11:41 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2020-10-21 14:59:35 +08:00
|
|
|
|
2020-08-19 10:41:19 +08:00
|
|
|
return output.String(), nil
|
2020-07-29 17:11:41 +08:00
|
|
|
}
|