feature 1.1.5 (#411)

This commit is contained in:
anqiansong
2021-03-01 17:29:07 +08:00
committed by GitHub
parent 791e76bcf0
commit d894b88c3e
27 changed files with 1037 additions and 443 deletions

View File

@@ -99,10 +99,10 @@ func (g *defaultGenerator) StartFromDDL(source string, withCache bool) error {
return g.createFile(modelList)
}
func (g *defaultGenerator) StartFromInformationSchema(db string, columns map[string][]*model.Column, withCache bool) error {
func (g *defaultGenerator) StartFromInformationSchema(tables map[string]*model.Table, withCache bool) error {
m := make(map[string]string)
for tableName, column := range columns {
table, err := parser.ConvertColumn(db, tableName, column)
for _, each := range tables {
table, err := parser.ConvertDataType(each)
if err != nil {
return err
}
@@ -182,10 +182,12 @@ func (g *defaultGenerator) genFromDDL(source string, withCache bool) (map[string
if err != nil {
return nil, err
}
code, err := g.genModel(*table, withCache)
if err != nil {
return nil, err
}
m[table.Name.Source()] = code
}
@@ -195,8 +197,9 @@ func (g *defaultGenerator) genFromDDL(source string, withCache bool) (map[string
// Table defines mysql table
type Table struct {
parser.Table
CacheKey map[string]Key
ContainsUniqueKey bool
PrimaryCacheKey Key
UniqueCacheKey []Key
ContainsUniqueCacheKey bool
}
func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, error) {
@@ -204,10 +207,7 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
return "", fmt.Errorf("table %s: missing primary key", in.Name.Source())
}
m, err := genCacheKeys(in)
if err != nil {
return "", err
}
primaryKey, uniqueKey := genCacheKeys(in)
importsCode, err := genImports(withCache, in.ContainsTime())
if err != nil {
@@ -216,15 +216,9 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
var table Table
table.Table = in
table.CacheKey = m
var containsUniqueCache = false
for _, item := range table.Fields {
if item.IsUniqueKey {
containsUniqueCache = true
break
}
}
table.ContainsUniqueKey = containsUniqueCache
table.PrimaryCacheKey = primaryKey
table.UniqueCacheKey = uniqueKey
table.ContainsUniqueCacheKey = len(uniqueKey) > 0
varsCode, err := genVars(table, withCache)
if err != nil {