You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
802 B
Go
37 lines
802 B
Go
4 years ago
|
package gen
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"strings"
|
||
|
"text/template"
|
||
|
|
||
|
sqltemplate "zero/tools/goctl/model/sql/template"
|
||
|
)
|
||
|
|
||
|
func genVars(table *InnerTable) (string, error) {
|
||
|
t, err := template.New("vars").Parse(sqltemplate.Vars)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
varBuffer := new(bytes.Buffer)
|
||
|
m, err := genCacheKeys(table)
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
keys := make([]string, 0)
|
||
|
for _, v := range m {
|
||
|
keys = append(keys, v.Expression)
|
||
|
}
|
||
|
err = t.Execute(varBuffer, map[string]interface{}{
|
||
|
"lowerObject": table.LowerCamelCase,
|
||
|
"upperObject": table.UpperCamelCase,
|
||
|
"createNotFound": table.CreateNotFound,
|
||
|
"keysDefine": strings.Join(keys, "\r\n"),
|
||
|
"snakePrimaryKey": table.PrimaryField.SnakeCase,
|
||
|
})
|
||
|
if err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
return varBuffer.String(), nil
|
||
|
}
|