reorganized sqlLogReplacements
This commit is contained in:
parent
613af90fac
commit
44007a7c8c
27
core/base.go
27
core/base.go
|
@ -1139,26 +1139,25 @@ func (app *BaseApp) initDataDB() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var sqlLogReplacements = map[*regexp.Regexp]string{
|
var sqlLogReplacements = []struct {
|
||||||
regexp.MustCompile(`[^'"]\{\{`): "`",
|
pattern *regexp.Regexp
|
||||||
regexp.MustCompile(`\}\}[^'"]`): "`",
|
replacement string
|
||||||
regexp.MustCompile(`[^'"]\[\[`): "`",
|
}{
|
||||||
regexp.MustCompile(`\]\][^'"]`): "`",
|
{regexp.MustCompile(`\[\[([^\[\]\{\}\.]+)\.([^\[\]\{\}\.]+)\]\]`), "`$1`.`$2`"},
|
||||||
regexp.MustCompile(`<nil>`): "NULL",
|
{regexp.MustCompile(`\{\{([^\[\]\{\}\.]+)\.([^\[\]\{\}\.]+)\}\}`), "`$1`.`$2`"},
|
||||||
|
{regexp.MustCompile(`([^'"])\{\{`), "$1`"},
|
||||||
|
{regexp.MustCompile(`\}\}([^'"])`), "`$1"},
|
||||||
|
{regexp.MustCompile(`([^'"])\[\[`), "$1`"},
|
||||||
|
{regexp.MustCompile(`\]\]([^'"])`), "`$1"},
|
||||||
|
{regexp.MustCompile(`<nil>`), "NULL"},
|
||||||
}
|
}
|
||||||
var sqlLogPrefixedTableIdentifierPattern = regexp.MustCompile(`\[\[([^\[\]\{\}\.]+)\.([^\[\]\{\}\.]+)\]\]`)
|
|
||||||
var sqlLogPrefixedColumnIdentifierPattern = regexp.MustCompile(`\{\{([^\[\]\{\}\.]+)\.([^\[\]\{\}\.]+)\}\}`)
|
|
||||||
|
|
||||||
// normalizeSQLLog replaces common query builder charactes with their plain SQL version for easier debugging.
|
// normalizeSQLLog replaces common query builder charactes with their plain SQL version for easier debugging.
|
||||||
// The query is still not suitable for execution and should be used only for log and debug purposes
|
// The query is still not suitable for execution and should be used only for log and debug purposes
|
||||||
// (the normalization is done here to avoid breaking changes in dbx).
|
// (the normalization is done here to avoid breaking changes in dbx).
|
||||||
func normalizeSQLLog(sql string) string {
|
func normalizeSQLLog(sql string) string {
|
||||||
sql = sqlLogPrefixedTableIdentifierPattern.ReplaceAllString(sql, "`$1`.`$2`")
|
for _, item := range sqlLogReplacements {
|
||||||
|
sql = item.pattern.ReplaceAllString(sql, item.replacement)
|
||||||
sql = sqlLogPrefixedColumnIdentifierPattern.ReplaceAllString(sql, "`$1`.`$2`")
|
|
||||||
|
|
||||||
for pattern, replacement := range sqlLogReplacements {
|
|
||||||
sql = pattern.ReplaceAllString(sql, replacement)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sql
|
return sql
|
||||||
|
|
Loading…
Reference in New Issue