forked from mattatcha/scaneo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmpl.go
39 lines (33 loc) · 787 Bytes
/
tmpl.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
37
38
39
package main
const (
scansText = `{{define "scans"}}// DON'T EDIT *** generated by scaneo *** DON'T EDIT //
package {{.PackageName}}
import "database/sql"
{{range .Tokens}}func {{$.Visibility}}can{{title .Name}}(r *sql.Row) ({{.Name}}, error) {
var s {{.Name}}
if err := r.Scan({{range .Fields}}
&s.{{.Name}},{{end}}
); err != nil {
return {{.Name}}{}, err
}
return s, nil
}
func {{$.Visibility}}can{{title .Name}}s(rs *sql.Rows) ([]{{.Name}}, error) {
structs := make([]{{.Name}}, 0, 16)
var err error
for rs.Next() {
var s {{.Name}}
if err = rs.Scan({{range .Fields}}
&s.{{.Name}},{{end}}
); err != nil {
return nil, err
}
structs = append(structs, s)
}
if err = rs.Err(); err != nil {
return nil, err
}
return structs, nil
}
{{end}}{{end}}`
)