sqlx: optimize sql generate logic

r/paopao-ce-plus
Michael Li 1 year ago
parent 05230212f2
commit 97c1d35bca
No known key found for this signature in database

@ -18,7 +18,23 @@ import (
func main() {
log.Println("[Yesql] generate code start")
yesql.SetDefaultQueryHook(func(query *yesql.Query) (*yesql.Query, error) {
query.Query = strings.TrimRight(query.Query, ";")
buf := strings.Builder{}
buf.Grow(len(query.Query))
// 去除多余的空格
isPrevSpace := false
for _, c := range query.Query {
switch c {
case ' ', '\t':
if !isPrevSpace {
buf.WriteRune(' ')
isPrevSpace = true
}
default:
buf.WriteRune(c)
isPrevSpace = false
}
}
query.Query = strings.TrimRight(buf.String(), ";")
return query, nil
})
if err := yesql.Generate(); err != nil {

Loading…
Cancel
Save