Library Panels: Add name endpoint & unique name validation to AddLibraryPanelModal (#33987)
This commit is contained in:
@@ -8,6 +8,28 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
)
|
||||
|
||||
type Pair struct {
|
||||
key string
|
||||
value interface{}
|
||||
}
|
||||
|
||||
func selectLibraryElementByParam(params []Pair) (string, []interface{}) {
|
||||
conditions := make([]string, 0, len(params))
|
||||
values := make([]interface{}, 0, len(params))
|
||||
for _, p := range params {
|
||||
conditions = append(conditions, "le."+p.key+"=?")
|
||||
values = append(values, p.value)
|
||||
}
|
||||
return ` WHERE ` + strings.Join(conditions, " AND "), values
|
||||
}
|
||||
|
||||
func writeParamSelectorSQL(builder *sqlstore.SQLBuilder, params ...Pair) {
|
||||
if len(params) > 0 {
|
||||
conditionString, paramValues := selectLibraryElementByParam(params)
|
||||
builder.Write(conditionString, paramValues...)
|
||||
}
|
||||
}
|
||||
|
||||
func writePerPageSQL(query searchLibraryElementsQuery, sqlStore *sqlstore.SQLStore, builder *sqlstore.SQLBuilder) {
|
||||
if query.perPage != 0 {
|
||||
offset := query.perPage * (query.page - 1)
|
||||
|
||||
Reference in New Issue
Block a user