mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
fix goctl model (#61)
This commit is contained in:
parent
e1d942a799
commit
ce5961a7d0
@ -22,7 +22,7 @@ func genDelete(table Table, withCache bool) (string, error) {
|
|||||||
}
|
}
|
||||||
var containsIndexCache = false
|
var containsIndexCache = false
|
||||||
for _, item := range table.Fields {
|
for _, item := range table.Fields {
|
||||||
if item.IsKey && !item.IsPrimaryKey {
|
if item.IsUniqueKey {
|
||||||
containsIndexCache = true
|
containsIndexCache = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ func genFineOneByField(table Table, withCache bool) (string, error) {
|
|||||||
var list []string
|
var list []string
|
||||||
camelTableName := table.Name.ToCamel()
|
camelTableName := table.Name.ToCamel()
|
||||||
for _, field := range table.Fields {
|
for _, field := range table.Fields {
|
||||||
if field.IsPrimaryKey || !field.IsKey {
|
if field.IsPrimaryKey || !field.IsUniqueKey {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
camelFieldName := field.Name.ToCamel()
|
camelFieldName := field.Name.ToCamel()
|
||||||
|
@ -29,9 +29,7 @@ func genCacheKeys(table parser.Table) (map[string]Key, error) {
|
|||||||
camelTableName := table.Name.ToCamel()
|
camelTableName := table.Name.ToCamel()
|
||||||
lowerStartCamelTableName := stringx.From(camelTableName).UnTitle()
|
lowerStartCamelTableName := stringx.From(camelTableName).UnTitle()
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
if !field.IsKey {
|
if field.IsUniqueKey || field.IsPrimaryKey {
|
||||||
continue
|
|
||||||
}
|
|
||||||
camelFieldName := field.Name.ToCamel()
|
camelFieldName := field.Name.ToCamel()
|
||||||
lowerStartCamelFieldName := stringx.From(camelFieldName).UnTitle()
|
lowerStartCamelFieldName := stringx.From(camelFieldName).UnTitle()
|
||||||
left := fmt.Sprintf("cache%s%sPrefix", camelTableName, camelFieldName)
|
left := fmt.Sprintf("cache%s%sPrefix", camelTableName, camelFieldName)
|
||||||
@ -47,5 +45,6 @@ func genCacheKeys(table parser.Table) (map[string]Key, error) {
|
|||||||
RespKeyExpression: fmt.Sprintf(`%s := fmt.Sprintf("%s%s", %s,resp.%s)`, variable, "%s", "%v", left, camelFieldName),
|
RespKeyExpression: fmt.Sprintf(`%s := fmt.Sprintf("%s%s", %s,resp.%s)`, variable, "%s", "%v", left, camelFieldName),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ type (
|
|||||||
DataType string
|
DataType string
|
||||||
IsKey bool
|
IsKey bool
|
||||||
IsPrimaryKey bool
|
IsPrimaryKey bool
|
||||||
|
IsUniqueKey bool
|
||||||
Comment string
|
Comment string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +125,7 @@ func Parse(ddl string) (*Table, error) {
|
|||||||
if ok {
|
if ok {
|
||||||
field.IsKey = true
|
field.IsKey = true
|
||||||
field.IsPrimaryKey = key == primary
|
field.IsPrimaryKey = key == primary
|
||||||
|
field.IsUniqueKey = key == unique
|
||||||
if field.IsPrimaryKey {
|
if field.IsPrimaryKey {
|
||||||
primaryKey.Field = field
|
primaryKey.Field = field
|
||||||
if column.Type.Autoincrement {
|
if column.Type.Autoincrement {
|
||||||
|
Loading…
Reference in New Issue
Block a user