forked from gnormal/gnorm
/
config.go
150 lines (131 loc) · 7.03 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package cli
// Config holds the schema that is expected to exist in the gnorm.toml file.
type Config struct {
// ConnStr is the connection string for the database. Environment variables
// in $FOO form will be expanded.
ConnStr string
// The type of DB you're connecting to. Currently the possible values are
// "postgres" or "mysql".
DBType string
// Schemas holds the names of schemas to generate code for.
Schemas []string
// IncludeTables is a whitelist of tables to generate data for. Tables not
// in this list will not be included in data geenrated by gnorm. You cannot
// set IncludeTables if ExcludeTables is set. By default, tables will be
// included in all schemas. To specify tables for a specific schema only,
// use the schema.tablenmae format.
IncludeTables []string
// ExcludeTables is a blacklist of tables to ignore while generating data.
// All tables in a schema that are not in this list will be used for
// generation. You cannot set ExcludeTables if IncludeTables is set. By
// default, tables will be excluded from all schemas. To specify tables for
// a specific schema only, use the schema.tablenmae format.
ExcludeTables []string
// 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 []string
// 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
}
// PostRun is a command with arguments that is run after each file is
// generated by GNORM. It is generally used to reformat the file, but it
// can be for any use. Environment variables will be expanded, and the
// special $GNORMFILE environment variable may be used, which will expand to
// the name of the file that was just generated.
PostRun []string
// 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 string
// TablePaths is a set of "output-path" = "template-path" pairs that tells
// Gnorm how to render and output its table info. Each template will be
// rendered with each table in turn and written out to the given output
// path. If no pairs are specified, tables will not be rendered.
//
// The table path may be a template, in which case the values .Schema and
// .Table may be referenced, containing the name of the current schema and
// table being rendered. For example,
// "{{.Schema}}/{{.Table}}/{{.Table}}.go" = "tables.gotmpl" would render
// tables.gotmpl template with data from the the "public.users" table to
// ./public/users/users.go.
TablePaths map[string]string
// SchemaPaths is a set of "output-path" = "template-path" pairs that tells
// Gnorm how to render and output its schema info. Each template will be
// rendered with each schema in turn and written out to the given output
// path. If no pairs are specified, schemas will not be rendered.
//
// The schema path may be a template, in which case the value .Schema may be
// referenced, containing the name of the current schema being rendered. For
// example, "schemas/{{.Schema}}/{{.Schema}}.go" = "schemas.gotmpl" would
// render schemas.gotmpl template with the "public" schema and output to
// ./schemas/public/public.go
SchemaPaths map[string]string
// EnumPaths is a set of "output-path" = "template-path" pairs that tells
// Gnorm how to render and output its enum info. Each template will be
// rendered with each enum in turn and written out to the given output path.
// If no pairs are specified, enums will not be rendered.
//
// The enum path may be a template, in which case the values .Schema and
// .Enum may be referenced, containing the name of the current schema and
// Enum being rendered. For example, "gnorm/{{.Schema}}/enums/{{.Enum}}.go"
// = "enums.gotmpl" would render the enums.gotmpl template with data from
// the "public.book_type" enum to ./gnorm/public/enums/users.go.
EnumPaths map[string]string
// TypeMap is a mapping of database type names to replacement type names
// (generally types from your language for deserialization). Types not in
// this list will remain in their database form. In the data sent to your
// template, this is the Column.Type, and the original type is in
// Column.OrigType. Note that because of the way tables in TOML work,
// TypeMap and NullableTypeMap must be at the end of your configuration
// file.
TypeMap map[string]string
// NullableTypeMap is a mapping of database type names to replacement type
// names (generally types from your language for deserialization)
// specifically for database columns that are nullable. Types not in this
// list will remain in their database form. In the data sent to your
// template, this is the Column.Type, and the original type is in
// Column.OrigType. Note that because of the way tables in TOML work,
// TypeMap and NullableTypeMap must be at the end of your configuration
// file.
NullableTypeMap map[string]string
// 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{}
// PluginDirs a list of paths that will be used for finding plugins. The
// list will be traversed in order, looking for a specifically named plugin.
// The first plugin that is found will be the one used.
PluginDirs []string
// OutputDir is the directory relative to the project root (where the
// gnorm.toml file is located) in which all the generated files are written
// to.
//
// This defaults to the current working directory i.e the directory in which
// gnorm.toml is found.
OutputDir string
// StaticDir is the directory relative to the project root (where the
// gnorm.toml file is located) in which all static files , which are
// intended to be copied to the OutputDir are found.
//
// The directory structure is preserved when copying the files to the
// OutputDir
StaticDir string
// NoOverwriteGlobs is a list of globs
// (https://golang.org/pkg/path/filepath/#Match). If a filename matches a glob
// *and* a file exists with that name, it will not be generated.
NoOverwriteGlobs []string
}