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
795 B
35 lines
795 B
package core |
|
|
|
import ( |
|
"fmt" |
|
"git.diulo.com/mogfee/kit/mysql/ddl" |
|
"git.diulo.com/mogfee/kit/stringx" |
|
"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) |
|
}
|
|
|