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.

53 lines
1.1 KiB

1 year ago
package gen
import "git.diulo.com/mogfee/kit/mysql/ddl"
type (
defaultGenerator struct {
dir string
pkg string
ignoreColumns []string
}
code struct {
importsCode string
varsCode string
typesCode string
newCode string
insertCode string
findCode string
updateCode string
deleteCode string
cacheExtra string
tableName string
}
codeTuple struct {
modelCode string
modelCustomCode string
}
)
func NewGenerator() *defaultGenerator {
return &defaultGenerator{}
}
func (g *defaultGenerator) StartFromDDL(filename string, withCache, strict bool, database string) error {
modelList, err := g.genFromDDL(filename, withCache, strict, database)
if err != nil {
return err
}
return g.createFile(modelList)
}
func (g *defaultGenerator) genFromDDL(filename string, cache bool, strict bool, database string) (
map[string]*codeTuple, error) {
m := make(map[string]*codeTuple)
err := ddl.Parser(filename, func(table *ddl.Table) error {
code, err := g.genModel(e, cache)
if err != nil {
return err
}
})
return m, err
}