K8s/Dashboards: Fix dashboard list and add tests (#91523)

This commit is contained in:
Ryan McKinley
2024-08-07 13:43:13 +03:00
committed by GitHub
parent e8d5d5fbff
commit 9e116d13a5
25 changed files with 740 additions and 138 deletions
@@ -14,8 +14,25 @@ var MySQL = mysql{
var _ Dialect = MySQL
type mysql struct {
standardIdent
backtickIdent
rowLockingClauseMap
argPlaceholderFunc
name
}
// standardIdent provides standard SQL escaping of identifiers.
type backtickIdent struct{}
var standardFallback = standardIdent{}
func (backtickIdent) Ident(s string) (string, error) {
switch s {
// Internal identifiers require backticks to work properly
case "user":
return "`" + s + "`", nil
case "":
return "", ErrEmptyIdent
}
// standard
return standardFallback.Ident(s)
}
@@ -116,6 +116,22 @@ func FormatSQL(q string) string {
return q
}
// RemoveEmptyLines removes the empty lines from a SQL statement
// empty lines are typical when using text template formatting
func RemoveEmptyLines(q string) string {
var b strings.Builder
lines := strings.Split(strings.ReplaceAll(q, "\r\n", "\n"), "\n")
for _, line := range lines {
if strings.TrimSpace(line) == "" {
continue
}
line = strings.ReplaceAll(line, "\t", " ")
b.WriteString(line)
b.WriteByte('\n')
}
return b.String()
}
type reFormatting struct {
re *regexp.Regexp
replacement string