Skip to content

Commit

Permalink
fix: extend query with metadata field (#21082)
Browse files Browse the repository at this point in the history
Co-authored-by: Qiu Jian <[email protected]>
  • Loading branch information
swordqiu and Qiu Jian authored Aug 23, 2024
1 parent 4e7b966 commit 7072126
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/cloudcommon/db/metadataresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ func ObjectIdQueryWithTagFilters(ctx context.Context, q *sqlchemy.SQuery, idFiel
return q
}

func ExtendQueryWithTag(ctx context.Context, q *sqlchemy.SQuery, idField string, modelName string, key string, fieldLabel string) *sqlchemy.SQuery {
manager := GetMetadaManagerInContext(ctx)
metadataQ := manager.Query().Equals("obj_type", modelName).Equals("key", key)
metadataQ = metadataQ.AppendField(metadataQ.Field("value").Label(fieldLabel))
metadataResQ := metadataQ.SubQuery()

q = q.LeftJoin(metadataResQ, sqlchemy.Equals(q.Field(idField), metadataResQ.Field("obj_id")))
q = q.AppendField(metadataResQ.Field(fieldLabel).Label(fieldLabel))

return q
}

func objIdQueryWithTags(ctx context.Context, objIdSubQ *sqlchemy.SSubQuery, idField string, modelName string, tagsList []map[string][]string) *sqlchemy.SQuery {
manager := GetMetadaManagerInContext(ctx)
metadataResQ := manager.Query().Equals("obj_type", modelName).SubQuery()
Expand Down

0 comments on commit 7072126

Please sign in to comment.