-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmd.go
More file actions
45 lines (37 loc) · 927 Bytes
/
md.go
File metadata and controls
45 lines (37 loc) · 927 Bytes
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
package main
import (
"io"
"golang.org/x/exp/slices"
)
func md(w io.Writer, tables Tables, section int) error {
t, err := newTemplate(mdTemplate)
if err != nil {
return err
}
slices.SortFunc(tables, func(a, b Table) bool {
return a.Name < b.Name
})
return t.Execute(w, struct {
Tables Tables
Section int
}{
Tables: tables,
Section: section,
})
}
var mdTemplate = `
{{range $i, $t := .Tables }}
{{- if eq $.Section 1 }}# {{end -}}
{{- if eq $.Section 2 }}## {{end -}}
{{- if eq $.Section 3 }}### {{end -}}
{{- if eq $.Section 4 }}#### {{end -}}
{{- if eq $.Section 5 }}##### {{end -}}
{{- if eq $.Section 6 }}###### {{end -}}
{{$t.Name}}
| Column | Type | Default | Refers |
| ------ | ---- | ------- | ------ |
{{range $j, $c := $t.Columns -}}
| {{$c.Name}}{{if $c.PrimaryKey}} (pk){{end}} | {{$c.Type}} | {{$c.Default}}{{if not $c.NotNull}} (nullable){{end}} | {{fk $t $c}} |
{{end}}
{{end}}
`