mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-31 00:34:25 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c1bae60c9 | ||
|
|
06b2404c0c |
@@ -147,8 +147,11 @@ func (b *BunSelectQuery) Column(columns ...string) common.SelectQuery {
|
||||
}
|
||||
|
||||
func (b *BunSelectQuery) ColumnExpr(query string, args ...interface{}) common.SelectQuery {
|
||||
b.query = b.query.ColumnExpr(query, args)
|
||||
|
||||
if len(args) > 0 {
|
||||
b.query = b.query.ColumnExpr(query, args)
|
||||
} else {
|
||||
b.query = b.query.ColumnExpr(query)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,12 @@ func (g *GormSelectQuery) Column(columns ...string) common.SelectQuery {
|
||||
}
|
||||
|
||||
func (g *GormSelectQuery) ColumnExpr(query string, args ...interface{}) common.SelectQuery {
|
||||
g.db = g.db.Select(query, args...)
|
||||
if len(args) > 0 {
|
||||
g.db = g.db.Select(query, args...)
|
||||
} else {
|
||||
g.db = g.db.Select(query)
|
||||
}
|
||||
|
||||
return g
|
||||
}
|
||||
|
||||
|
||||
@@ -1816,23 +1816,52 @@ func (h *Handler) generateMetadata(schema, entity string, model interface{}) *co
|
||||
if modelType.Kind() != reflect.Struct {
|
||||
logger.Error("Model type must be a struct, got %s for %s.%s", modelType.Kind(), schema, entity)
|
||||
return &common.TableMetadata{
|
||||
Schema: schema,
|
||||
Table: h.getTableName(schema, entity, model),
|
||||
Columns: []common.Column{},
|
||||
Schema: schema,
|
||||
Table: h.getTableName(schema, entity, model),
|
||||
Columns: []common.Column{},
|
||||
Relations: []string{},
|
||||
}
|
||||
}
|
||||
|
||||
tableName := h.getTableName(schema, entity, model)
|
||||
|
||||
metadata := &common.TableMetadata{
|
||||
Schema: schema,
|
||||
Table: tableName,
|
||||
Columns: []common.Column{},
|
||||
Schema: schema,
|
||||
Table: tableName,
|
||||
Columns: []common.Column{},
|
||||
Relations: []string{},
|
||||
}
|
||||
|
||||
for i := 0; i < modelType.NumField(); 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
|
||||
columnName := field.Tag.Get("gorm")
|
||||
if strings.Contains(columnName, "column:") {
|
||||
@@ -1844,15 +1873,9 @@ func (h *Handler) generateMetadata(schema, entity string, model interface{}) *co
|
||||
}
|
||||
}
|
||||
} else {
|
||||
columnName = field.Tag.Get("json")
|
||||
if columnName == "" || columnName == "-" {
|
||||
columnName = strings.ToLower(field.Name)
|
||||
}
|
||||
columnName = jsonName
|
||||
}
|
||||
|
||||
// Check for primary key and unique constraint
|
||||
gormTag := field.Tag.Get("gorm")
|
||||
|
||||
column := common.Column{
|
||||
Name: columnName,
|
||||
Type: h.getColumnType(field.Type),
|
||||
|
||||
Reference in New Issue
Block a user