mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-12-24 10:40:55 +08:00
style: move the initialization database code to internal/database and add the sgorm library
This commit is contained in:
@@ -63,6 +63,10 @@ func setCrudInfo(field tmplField) *CrudInfo {
|
||||
}
|
||||
|
||||
func newCrudInfo(data tmplData) *CrudInfo {
|
||||
if len(data.Fields) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var info *CrudInfo
|
||||
for _, field := range data.Fields {
|
||||
if field.IsPrimaryKey {
|
||||
@@ -81,7 +85,7 @@ func newCrudInfo(data tmplData) *CrudInfo {
|
||||
}
|
||||
}
|
||||
|
||||
// if not found xxx_id field, use the first column as primary key
|
||||
// if not found xxx_id field, use the first field of integer or string type
|
||||
if info == nil {
|
||||
for _, field := range data.Fields {
|
||||
if isDesiredGoType(field.GoType) {
|
||||
@@ -89,11 +93,11 @@ func newCrudInfo(data tmplData) *CrudInfo {
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(data.Fields) > 0 {
|
||||
info = setCrudInfo(data.Fields[0])
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// use the first column as primary key
|
||||
if info == nil {
|
||||
info = setCrudInfo(data.Fields[0])
|
||||
}
|
||||
|
||||
info.TableNameCamel = data.TableName
|
||||
|
||||
Reference in New Issue
Block a user