🐞 fix(gen): pg gen of insert (#1591)
Co-authored-by: kurimi1 <d0n41df@gmail.com>
This commit is contained in:
@@ -223,7 +223,7 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
|
||||
table.UniqueCacheKey = uniqueKey
|
||||
table.ContainsUniqueCacheKey = len(uniqueKey) > 0
|
||||
|
||||
importsCode, err := genImports(withCache, in.ContainsTime(), table)
|
||||
importsCode, err := genImports(withCache, in.ContainsTime(), table, g.isPostgreSql)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/tools/goctl/util/pathx"
|
||||
)
|
||||
|
||||
func genImports(withCache, timeImport bool, table Table) (string, error) {
|
||||
func genImports(withCache, timeImport bool, table Table, postgreSql bool) (string, error) {
|
||||
if withCache {
|
||||
text, err := pathx.LoadTemplate(category, importsTemplateFile, template.Imports)
|
||||
if err != nil {
|
||||
@@ -23,10 +23,18 @@ func genImports(withCache, timeImport bool, table Table) (string, error) {
|
||||
|
||||
return buffer.String(), nil
|
||||
}
|
||||
|
||||
text, err := pathx.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCache)
|
||||
if err != nil {
|
||||
return "", err
|
||||
var text string
|
||||
var err error
|
||||
if postgreSql {
|
||||
text, err = pathx.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCachePg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
text, err = pathx.LoadTemplate(category, importsWithNoCacheTemplateFile, template.ImportsNoCache)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
|
||||
|
||||
@@ -46,9 +46,19 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error)
|
||||
}
|
||||
|
||||
camel := table.Name.ToCamel()
|
||||
text, err := pathx.LoadTemplate(category, insertTemplateFile, template.Insert)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
var text string
|
||||
var err error
|
||||
// if database is postgresql
|
||||
if postgreSql {
|
||||
text, err = pathx.LoadTemplate(category, insertTemplateFile, template.InsertPg)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
} else {
|
||||
text, err = pathx.LoadTemplate(category, insertTemplateFile, template.Insert)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
}
|
||||
|
||||
output, err := util.With("insert").
|
||||
@@ -69,9 +79,17 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error)
|
||||
}
|
||||
|
||||
// interface method
|
||||
text, err = pathx.LoadTemplate(category, insertTemplateMethodFile, template.InsertMethod)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
// if database is postgresql
|
||||
if postgreSql {
|
||||
text, err = pathx.LoadTemplate(category, insertTemplateMethodFile, template.InsertMethodPg)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
} else {
|
||||
text, err = pathx.LoadTemplate(category, insertTemplateMethodFile, template.InsertMethod)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
}
|
||||
|
||||
insertMethodOutput, err := util.With("insertMethod").Parse(text).Execute(map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user