2020-07-29 17:11:41 +08:00
|
|
|
package gen
|
|
|
|
|
|
|
|
import (
|
2022-01-25 23:15:07 +08:00
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/model/sql/template"
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/util"
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
2020-07-29 17:11:41 +08:00
|
|
|
)
|
|
|
|
|
2022-04-01 22:19:52 +08:00
|
|
|
func genImports(table Table, withCache, timeImport bool) (string, error) {
|
2020-08-19 10:41:19 +08:00
|
|
|
if withCache {
|
2022-01-03 21:32:40 +08:00
|
|
|
text, err := pathx.LoadTemplate(category, importsTemplateFile, template.Imports)
|
2020-10-21 14:59:35 +08:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2023-01-24 16:32:02 +08:00
|
|
|
buffer, err := util.With("import").Parse(text).Execute(map[string]any{
|
2022-10-25 06:58:51 +08:00
|
|
|
"time": timeImport,
|
|
|
|
"containsPQ": table.ContainsPQ,
|
|
|
|
"data": table,
|
2020-09-03 13:57:28 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2020-10-21 14:59:35 +08:00
|
|
|
|
2020-09-03 13:57:28 +08:00
|
|
|
return buffer.String(), nil
|
2021-02-09 13:50:21 +08:00
|
|
|
}
|
2022-03-01 20:27:59 +08:00
|
|
|
|
|
|
|
text, err := pathx.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCache)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2021-02-09 13:50:21 +08:00
|
|
|
}
|
2020-10-21 14:59:35 +08:00
|
|
|
|
2023-01-24 17:51:03 +08:00
|
|
|
buffer, err := util.With("import").Parse(text).Execute(map[string]any{
|
2022-10-25 06:58:51 +08:00
|
|
|
"time": timeImport,
|
|
|
|
"containsPQ": table.ContainsPQ,
|
|
|
|
"data": table,
|
2021-02-09 13:50:21 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2020-07-29 17:11:41 +08:00
|
|
|
}
|
2021-02-09 13:50:21 +08:00
|
|
|
|
|
|
|
return buffer.String(), nil
|
2020-07-29 17:11:41 +08:00
|
|
|
}
|