This repository was archived by the owner on Nov 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtemplate.go
More file actions
80 lines (59 loc) · 2.09 KB
/
Copy pathtemplate.go
File metadata and controls
80 lines (59 loc) · 2.09 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
const tFile = `
// Code generated by sprocbind, DO NOT EDIT.
package {{.packageName}}
{{if .procedures}}
import (
"context"
"database/sql"
"github.com/jmoiron/sqlx"
)
// Procedures
type Queryer interface {
QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
}
{{range $procedure := .procedures}}
// {{GoName $procedure.Name}} calls the stored procedure {{Clean $procedure.Name}}
func {{GoName $procedure.Name}}(ctx context.Context, db Queryer{{range $param := $procedure.Params}}, {{GoNameLower $param.Name}} {{GoDataType $param.DataType}}{{end}}) (*sqlx.Rows, error) {
// TODO: Add tracing/timing here.
return db.QueryxContext(ctx,
"exec {{Clean $procedure.Name}} {{range $i, $param := $procedure.Params}}{{if gt $i 0}}, {{end}}@{{Clean $param.Name}}{{end}}"{{range $i, $param := $procedure.Params}},
sql.Named("{{Clean $param.Name}}", {{GoNameLower $param.Name}}){{end}})
}
{{end}}
{{end}}
{{if .normalTables}}
// Tables
{{range $table := .normalTables}}
type {{GoName $table.Name}} struct {
{{range $col := $table.Columns}}
{{GoName $col.Name}} *{{GoDataType $col.DataType}} ` + "`" + `db:"{{Clean $col.Name}}"` + "`" + `
{{end}}
}
{{end}}
{{end}}
{{if .tables}}
// Table Types
{{range $table := .tables}}
type {{GoName $table.Name}} []{{GoName $table.Name}}Row
func (t *{{GoName $table.Name}}) TVP() (typeName string, exampleRow []interface{}, rows [][]interface{}) {
typeName = "{{Clean $table.Name}}"
//columnNames = []string{ {{range $i, $col := $table.Columns}}{{if gt $i 0}}, {{end}}"{{Clean $col.Name}}"{{end}} }
var v []{{GoName $table.Name}}Row
if t != nil {
v = *t
}
for _, r := range append(v, {{GoName $table.Name}}Row{}) {
rows = append(rows, []interface{}{ {{range $col := $table.Columns}}
r.{{GoName $col.Name}},{{end}}
})
}
exampleRow = rows[len(rows)-1]
rows = rows[:len(rows)-1]
return
}
type {{GoName $table.Name}}Row struct {
{{range $col := $table.Columns}} {{GoName $col.Name}} {{GoDataType $col.DataType}} ` + "`" + `db:"{{Clean $col.Name}}"` + "`" + `
{{end}}}
{{end}}
{{end}}`