|
|
@ -126,7 +126,12 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
importsCode := genImports(withCache)
|
|
|
|
|
|
|
|
|
|
|
|
importsCode, err := genImports(withCache, in.ContainsTime())
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return "", err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var table Table
|
|
|
|
var table Table
|
|
|
|
table.Table = in
|
|
|
|
table.Table = in
|
|
|
|
table.CacheKey = m
|
|
|
|
table.CacheKey = m
|
|
|
@ -135,36 +140,44 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typesCode, err := genTypes(table, withCache)
|
|
|
|
typesCode, err := genTypes(table, withCache)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
newCode, err := genNew(table, withCache)
|
|
|
|
newCode, err := genNew(table, withCache)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
insertCode, err := genInsert(table, withCache)
|
|
|
|
insertCode, err := genInsert(table, withCache)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var findCode = make([]string, 0)
|
|
|
|
var findCode = make([]string, 0)
|
|
|
|
findOneCode, err := genFindOne(table, withCache)
|
|
|
|
findOneCode, err := genFindOne(table, withCache)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
findOneByFieldCode, err := genFineOneByField(table, withCache)
|
|
|
|
findOneByFieldCode, err := genFineOneByField(table, withCache)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
findCode = append(findCode, findOneCode, findOneByFieldCode)
|
|
|
|
findCode = append(findCode, findOneCode, findOneByFieldCode)
|
|
|
|
updateCode, err := genUpdate(table, withCache)
|
|
|
|
updateCode, err := genUpdate(table, withCache)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
deleteCode, err := genDelete(table, withCache)
|
|
|
|
deleteCode, err := genDelete(table, withCache)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
output, err := t.Execute(map[string]interface{}{
|
|
|
|
output, err := t.Execute(map[string]interface{}{
|
|
|
|
"imports": importsCode,
|
|
|
|
"imports": importsCode,
|
|
|
|
"vars": varsCode,
|
|
|
|
"vars": varsCode,
|
|
|
@ -178,5 +191,6 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return output.String(), nil
|
|
|
|
return output.String(), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|