forked from gocraft/dbr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comments.go
36 lines (31 loc) · 963 Bytes
/
comments.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package dbr
import "strings"
const (
openingSQLComment = "/*"
closingSQLComment = "*/"
space = " "
newline = "\n"
emptyString = ""
)
// Comments represents a set of sql comments
type Comments []string
// Append a new sql comment to a set of comments
func (comments Comments) Append(comment string) Comments {
comment = strings.Replace(comment, openingSQLComment, emptyString, -1)
comment = strings.Replace(comment, closingSQLComment, emptyString, -1)
comment = strings.TrimSpace(comment)
comments = append(comments, comment)
return comments
}
// Build writes each comment in the form of "/* some comment */\n"
func (comments Comments) Build(d Dialect, buf Buffer) error {
for _, comment := range comments {
words := []string{openingSQLComment, space, comment, space, closingSQLComment, newline}
for _, str := range words {
if _, err := buf.WriteString(str); err != nil {
return err
}
}
}
return nil
}