forked from gnormal/gnorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
84 lines (71 loc) · 3.34 KB
/
config.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
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
81
82
83
84
package run
import (
"text/template"
"github.com/episub/gnorm/database"
"github.com/episub/gnorm/run/data"
)
// Config holds the schema that is expected to exist in the gnorm.toml file.
type Config struct {
data.ConfigData
// TablePaths is a list of output targets used to render table data.
//
// The filename template may reference the values .Schema and .Table,
// containing the name of the current schema and table being rendered. For
// example, "{{.Schema}}/{{.Table}}/{{.Table}}.go" would render the
// "public.users" table to ./public/users/users.go.
TablePaths []OutputTarget
// SchemaPaths is a list of output targets used to render schema data.
//
// The filename template may reference the value .Schema, containing the
// name of the current schema being rendered. For example,
// "schemas/{{.Schema}}/{{.Schema}}.go" would render the "public" schema to
// ./schemas/public/public.go
SchemaPaths []OutputTarget
// EnumPaths is a list of output targets used to render enum data.
//
// The filename template may reference the values .Schema and .Enum,
// containing the name of the current schema and Enum being rendered. For
// example, "gnorm/{{.Schema}}/enums/{{.Enum}}.go" would render the
// "public.book_type" enum to ./gnorm/public/enums/users.go.
EnumPaths []OutputTarget
// NameConversion defines how the DBName of tables, schemas, and enums are
// converted into their Name value. This is a template that may use all the
// regular functions. The "." value is the DB name of the item. Thus, to
// make an item's Name the same as its DBName, you'd use a template of
// "{{.}}". To make the Name the PascalCase version of DBName, you'd use
// "{{pascal .}}".
NameConversion *template.Template
// Driver holds a reference to the current database driver that was
// registered for the DBType and can connect using ConnStr.
Driver database.Driver
// Params contains any data you may want to pass to your templates. This is
// a good way to make templates reusable with different configuration values
// for different situations. The values in this field will be available in
// the .Params value for all templates.
Params map[string]interface{}
// TemplateEngine, if specified, describes a command line tool to run to
// render your templates, allowing you to use your preferred templating
// engine. If not specified, go's text/template will be used to render.
TemplateEngine struct {
// CommandLine is the command to run to render the template. You may
// pass the following variables to the command line - {{.Data}} the name
// of a .json file containing the gnorm data serialized into json,
// {{.Template}} - the name of the template file being rendered,
// {{.Output}} the target file where output should be written.
// text/template.
CommandLine []*template.Template
// If true, the json data will be sent via stdin to the rendering tool.
UseStdin bool
// If true, the output of the tool will be written to the target file.
UseStdout bool
}
}
// OutputTarget contains a template that generates a filename to write to, and a
// template that generates the contents for that file. If an external template
// engine is used, Contents will be nil, and the template at ContentsPath should
// be used.
type OutputTarget struct {
Filename *template.Template
Contents *template.Template
ContentsPath string
}