|
|
|
@ -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 {
|
|
|
|
|