generator

package
v0.0.0-...-1e758dd Latest Latest
Warning

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

Go to latest
Published: May 10, 2017 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(writer io.Writer, db *sql.DB, pkg string, queries ...Query) error

Types

type Arg

type Arg struct {
	// argument name
	Name string `json:"name"`
	// argument value for sample query
	Sample string `json:"example"`
	// Dynamic arguments become "?" in the query and are provided at runtime.
	// Static arguments are identifiers and have to be known at query construction time
	// (e.g. table and schema name)
	Dynamic bool `json:"dynamic,omitempty"`
	// argument should be quoted
	Quoted bool `json:"quote,omitempty"`
	// argument type (string by default)
	Type reflect.Type `json:"-"`
	// alternatives
	ValueType interface{}            `json:"-"`
	Values    map[string]interface{} `json:"-"`
	// description
	Comment string `json:"-"`
}

Arg represents an argument in a MySQL query

func (*Arg) String

func (a *Arg) String() string

type Arglist

type Arglist []*Arg

Arglist represents a sequence of arguments

func (Arglist) Declaration

func (a Arglist) Declaration() string

func (Arglist) Dynamic

func (a Arglist) Dynamic() Arglist

func (Arglist) QuotedNames

func (a Arglist) QuotedNames() string

func (Arglist) Static

func (a Arglist) Static() Arglist

type Map

type Map func(name string, scope string) string

Map provides a name for a field in a scope ("go", "mysql", "json", "xml").

type Query

type Query []interface{}

Query represents a Query a struct should be generated for. It contains the name of the struct to be created as its first argument. The name may be followed by an optional map[int]string to override field names of the respective column indices. Following that are parts of the SQL (string) and Arg or *Arg (parameters).

func SQL

func SQL(structName string, parts ...interface{}) Query

SQL provides a simple routine to create a Query

func (Query) Args

func (q Query) Args() Arglist

func (Query) Overrides

func (q Query) Overrides(numCols int) []string

func (Query) Sample

func (q Query) Sample() (string, error)

func (Query) String

func (q Query) String() string

func (Query) StructName

func (q Query) StructName() (name string, ok bool)

type TemplateColumn

type TemplateColumn struct {
	mysqlinternals.Column
	// contains filtered or unexported fields
}

TemplateColumn contains all available information for a column retrievable from a mysql response. nameOverride is filled with the name to use if the one provided by MySQL should not be used

func (TemplateColumn) Bindable

func (c TemplateColumn) Bindable() bool

func (TemplateColumn) Declaration

func (c TemplateColumn) Declaration() (decl string, err error)

func (TemplateColumn) Goname

func (c TemplateColumn) Goname() string

func (TemplateColumn) Name

func (c TemplateColumn) Name() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL