run

package
Version: v0.0.0-...-f6175e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(env environ.Values, cfg *Config) error

Generate reads your database, gets the schema for it, and then generates files based on your templates and your configuration.

func Preview

func Preview(env environ.Values, cfg *Config, format PreviewFormat) error

Preview displays the database info that would be passed to your template based on your configuration.

Types

type Config

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
	}
}

Config holds the schema that is expected to exist in the gnorm.toml file.

type OutputTarget

type OutputTarget struct {
	Filename     *template.Template
	Contents     *template.Template
	ContentsPath string
}

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 PreviewFormat

type PreviewFormat int

PreviewFormat defines the types of output that Preview can return.

const (
	// PreviewTabular shows the data in textual tables.
	PreviewTabular PreviewFormat = iota
	// PreviewYAML shows the data in YAML.
	PreviewYAML
	// PreviewJSON shows the data in JSON.
	PreviewJSON
	// PreviewTypes just prints out the column types used by the DB.
	PreviewTypes
)

Directories

Path Synopsis
Package data supplies the data for gnorm templates
Package data supplies the data for gnorm templates

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL