You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
800 B

package core
import (
"fmt"
"git.diulo.com/mogfee/kit/core/stringx"
"git.diulo.com/mogfee/kit/mysql/ddl"
"html/template"
"io"
"strings"
)
func SaveFile(w io.Writer, templateContent string, table *ddl.Table) error {
tmp, err := template.New("").Funcs(map[string]any{
"UpperType": func(str string) string {
return stringx.Ucfirst(ddl.GoName(str))
},
"LowerType": func(str string) string {
if str == "type" {
str = "vtype"
}
return stringx.Lcfirst(ddl.GoName(str))
},
"UpdateColumn": func(columns []*ddl.TableColumn) string {
arr := []string{}
for _, v := range columns {
arr = append(arr, fmt.Sprintf("%s=?", v.Name))
}
return strings.Join(arr, " and ")
},
}).Parse(templateContent)
if err != nil {
return err
}
return tmp.Execute(w, table)
}