goext/sq/commentTrimmer.go
Mike Schwörer 42424f4bc2
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m16s
v0.0.400 added CommentTrimmer and DBOptions to sq
2024-03-09 14:59:32 +01:00

33 lines
528 B
Go

package sq
import (
"context"
"strings"
)
var CommentTrimmer = NewPreListener(fnTrimComments)
func fnTrimComments(ctx context.Context, cmdtype string, id *uint16, sql *string, params *PP) error {
res := make([]string, 0)
for _, s := range strings.Split(*sql, "\n") {
if strings.HasPrefix(strings.TrimSpace(s), "--") {
continue
}
idx := strings.Index(s, "--")
if idx != -1 {
s = s[:idx]
}
s = strings.TrimRight(s, " \t\r\n")
res = append(res, s)
}
*sql = strings.Join(res, "\n")
return nil
}