mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
import package for no-pk models
This commit is contained in:
parent
c487e9d6f7
commit
82b7ab3e31
@ -487,10 +487,13 @@ func writeModelFiles(tables []*Table, mPath string, selectedTables map[string]bo
|
|||||||
fileStr = strings.Replace(fileStr, "{{modelName}}", camelCase(tb.Name), -1)
|
fileStr = strings.Replace(fileStr, "{{modelName}}", camelCase(tb.Name), -1)
|
||||||
// if table contains time field, import time.Time package
|
// if table contains time field, import time.Time package
|
||||||
timePkg := ""
|
timePkg := ""
|
||||||
|
importTimePkg := ""
|
||||||
if tb.ImportTimePkg {
|
if tb.ImportTimePkg {
|
||||||
timePkg = "\"time\"\n"
|
timePkg = "\"time\"\n"
|
||||||
|
importTimePkg = "import \"time\"\n"
|
||||||
}
|
}
|
||||||
fileStr = strings.Replace(fileStr, "{{timePkg}}", timePkg, -1)
|
fileStr = strings.Replace(fileStr, "{{timePkg}}", timePkg, -1)
|
||||||
|
fileStr = strings.Replace(fileStr, "{{importTimePkg}}", importTimePkg, -1)
|
||||||
if _, err := f.WriteString(fileStr); err != nil {
|
if _, err := f.WriteString(fileStr); err != nil {
|
||||||
ColorLog("[ERRO] Could not write model file to %s\n", fpath)
|
ColorLog("[ERRO] Could not write model file to %s\n", fpath)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
@ -707,6 +710,7 @@ func getPackagePath(curpath string) (packpath string) {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
STRUCT_MODEL_TPL = `package models
|
STRUCT_MODEL_TPL = `package models
|
||||||
|
{{importTimePkg}}
|
||||||
|
|
||||||
{{modelStruct}}
|
{{modelStruct}}
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user