Search (SQL): support dashboardUID query parameter (#50121)

This commit is contained in:
Ryan McKinley
2022-06-02 12:56:01 -07:00
committed by GitHub
parent bc8578524b
commit d452322aa8
6 changed files with 87 additions and 55 deletions

View File

@@ -95,14 +95,22 @@ func (f FolderFilter) Where() (string, []interface{}) {
return sqlIDin("dashboard.folder_id", f.IDs)
}
type DashboardFilter struct {
type DashboardIDFilter struct {
IDs []int64
}
func (f DashboardFilter) Where() (string, []interface{}) {
func (f DashboardIDFilter) Where() (string, []interface{}) {
return sqlIDin("dashboard.id", f.IDs)
}
type DashboardFilter struct {
UIDs []string
}
func (f DashboardFilter) Where() (string, []interface{}) {
return sqlUIDin("dashboard.uid", f.UIDs)
}
type TagsFilter struct {
Tags []string
}
@@ -150,6 +158,21 @@ func sqlIDin(column string, ids []int64) (string, []interface{}) {
return fmt.Sprintf("%s IN %s", column, sqlArray), params
}
func sqlUIDin(column string, uids []string) (string, []interface{}) {
length := len(uids)
if length < 1 {
return "", nil
}
sqlArray := "(?" + strings.Repeat(",?", length-1) + ")"
params := []interface{}{}
for _, id := range uids {
params = append(params, id)
}
return fmt.Sprintf("%s IN %s", column, sqlArray), params
}
// FolderWithAlertsFilter applies a filter that makes the result contain only folders that contain alert rules
type FolderWithAlertsFilter struct {
}