mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-06 14:26:22 +00:00
Added meta handlers
This commit is contained in:
parent
06b2404c0c
commit
7c1bae60c9
@ -1819,6 +1819,7 @@ func (h *Handler) generateMetadata(schema, entity string, model interface{}) *co
|
|||||||
Schema: schema,
|
Schema: schema,
|
||||||
Table: h.getTableName(schema, entity, model),
|
Table: h.getTableName(schema, entity, model),
|
||||||
Columns: []common.Column{},
|
Columns: []common.Column{},
|
||||||
|
Relations: []string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1828,11 +1829,39 @@ func (h *Handler) generateMetadata(schema, entity string, model interface{}) *co
|
|||||||
Schema: schema,
|
Schema: schema,
|
||||||
Table: tableName,
|
Table: tableName,
|
||||||
Columns: []common.Column{},
|
Columns: []common.Column{},
|
||||||
|
Relations: []string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < modelType.NumField(); i++ {
|
for i := 0; i < modelType.NumField(); i++ {
|
||||||
field := modelType.Field(i)
|
field := modelType.Field(i)
|
||||||
|
|
||||||
|
// Skip unexported fields
|
||||||
|
if !field.IsExported() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
gormTag := field.Tag.Get("gorm")
|
||||||
|
jsonTag := field.Tag.Get("json")
|
||||||
|
|
||||||
|
// Skip fields with json:"-"
|
||||||
|
if jsonTag == "-" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get JSON name
|
||||||
|
jsonName := strings.Split(jsonTag, ",")[0]
|
||||||
|
if jsonName == "" {
|
||||||
|
jsonName = field.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this is a relation field (slice or struct, but not time.Time)
|
||||||
|
if field.Type.Kind() == reflect.Slice ||
|
||||||
|
(field.Type.Kind() == reflect.Struct && field.Type.Name() != "Time") ||
|
||||||
|
(field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct && field.Type.Elem().Name() != "Time") {
|
||||||
|
metadata.Relations = append(metadata.Relations, jsonName)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Get column name from gorm tag or json tag
|
// Get column name from gorm tag or json tag
|
||||||
columnName := field.Tag.Get("gorm")
|
columnName := field.Tag.Get("gorm")
|
||||||
if strings.Contains(columnName, "column:") {
|
if strings.Contains(columnName, "column:") {
|
||||||
@ -1844,14 +1873,8 @@ func (h *Handler) generateMetadata(schema, entity string, model interface{}) *co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
columnName = field.Tag.Get("json")
|
columnName = jsonName
|
||||||
if columnName == "" || columnName == "-" {
|
|
||||||
columnName = strings.ToLower(field.Name)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Check for primary key and unique constraint
|
|
||||||
gormTag := field.Tag.Get("gorm")
|
|
||||||
|
|
||||||
column := common.Column{
|
column := common.Column{
|
||||||
Name: columnName,
|
Name: columnName,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user