boilingcore

package
v3.0.0-rc2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2018 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package boilingcore has types and methods useful for generating code that acts as a fully dynamic ORM might.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FillAliases

func FillAliases(a *Aliases, tables []drivers.Table)

FillAliases takes the table information from the driver and fills in aliases where the user has provided none.

This leaves us with a complete list of Go names for all tables, columns, and relationships.

Types

type Aliases

type Aliases struct {
	Tables map[string]TableAlias `toml:"tables,omitempty" json:"tables,omitempty"`
}

Aliases defines aliases for the generation run

func ConvertAliases

func ConvertAliases(i interface{}) (a Aliases)

ConvertAliases is necessary because viper

func (Aliases) ManyRelationship

func (a Aliases) ManyRelationship(table, fkey, joinTable, joinTableFKey string) RelationshipAlias

ManyRelationship looks up a relationship alias, panics if not found. It will first try to look up a join table relationship, then it will try a normal one-to-many relationship. That's to say joinTable/joinTableFKey are used if they're not empty.

This allows us to skip additional conditionals in the templates.

func (Aliases) Table

func (a Aliases) Table(table string) TableAlias

Table gets a table alias, panics if not found.

type Config

type Config struct {
	DriverName   string         `toml:"driver_name,omitempty" json:"driver_name,omitempty"`
	DriverConfig drivers.Config `toml:"driver_config,omitempty" json:"driver_config,omitempty"`

	PkgName          string   `toml:"pkg_name,omitempty" json:"pkg_name,omitempty"`
	OutFolder        string   `toml:"out_folder,omitempty" json:"out_folder,omitempty"`
	TemplateDirs     []string `toml:"template_dirs,omitempty" json:"template_dirs,omitempty"`
	Tags             []string `toml:"tags,omitempty" json:"tags,omitempty"`
	Replacements     []string `toml:"replacements,omitempty" json:"replacements,omitempty"`
	Debug            bool     `toml:"debug,omitempty" json:"debug,omitempty"`
	AddGlobal        bool     `toml:"add_global,omitempty" json:"add_global,omitempty"`
	AddPanic         bool     `toml:"add_panic,omitempty" json:"add_panic,omitempty"`
	NoContext        bool     `toml:"no_context,omitempty" json:"no_context,omitempty"`
	NoTests          bool     `toml:"no_tests,omitempty" json:"no_tests,omitempty"`
	NoHooks          bool     `toml:"no_hooks,omitempty" json:"no_hooks,omitempty"`
	NoAutoTimestamps bool     `toml:"no_auto_timestamps,omitempty" json:"no_auto_timestamps,omitempty"`
	NoRowsAffected   bool     `toml:"no_rows_affected,omitempty" json:"no_rows_affected,omitempty"`
	Wipe             bool     `toml:"wipe,omitempty" json:"wipe,omitempty"`
	StructTagCasing  string   `toml:"struct_tag_casing,omitempty" json:"struct_tag_casing,omitempty"`

	Imports importers.Collection `toml:"imports,omitempty" json:"imports,omitempty"`

	Aliases      Aliases       `toml:"aliases,omitempty" json:"aliases,omitempty"`
	TypeReplaces []TypeReplace `toml:"type_replaces,omitempty" json:"type_replaces,omitempty"`
}

Config for the running of the commands

type RelationshipAlias

type RelationshipAlias struct {
	Local   string `toml:"local,omitempty" json:"local,omitempty"`
	Foreign string `toml:"foreign,omitempty" json:"foreign,omitempty"`
}

RelationshipAlias defines the naming for both sides of a foreign key.

type State

type State struct {
	Config *Config

	Driver  drivers.Interface
	Schema  string
	Tables  []drivers.Table
	Dialect drivers.Dialect

	Templates     *templateList
	TestTemplates *templateList
}

State holds the global data needed by most pieces to run

func New

func New(config *Config) (*State, error)

New creates a new state based off of the config

func (*State) Cleanup

func (s *State) Cleanup() error

Cleanup closes any resources that must be closed

func (*State) Run

func (s *State) Run() error

Run executes the sqlboiler templates and outputs them to files based on the state given.

type TableAlias

type TableAlias struct {
	UpPlural     string `toml:"up_plural,omitempty" json:"up_plural,omitempty"`
	UpSingular   string `toml:"up_singular,omitempty" json:"up_singular,omitempty"`
	DownPlural   string `toml:"down_plural,omitempty" json:"down_plural,omitempty"`
	DownSingular string `toml:"down_singular,omitempty" json:"down_singular,omitempty"`

	Columns       map[string]string            `toml:"columns,omitempty" json:"columns,omitempty"`
	Relationships map[string]RelationshipAlias `toml:"relationships,omitempty" json:"relationships,omitempty"`
}

TableAlias defines the spellings for a table name in Go

func (TableAlias) Column

func (t TableAlias) Column(column string) string

Column get's a column's aliased name, panics if not found.

func (TableAlias) Relationship

func (t TableAlias) Relationship(fkey string) RelationshipAlias

Relationship looks up a relationship, panics if not found.

type TypeReplace

type TypeReplace struct {
	Match   drivers.Column `toml:"match,omitempty" json:"match,omitempty"`
	Replace drivers.Column `toml:"replace,omitempty" json:"replace,omitempty"`
	Imports importers.Set  `toml:"imports,omitempty" json:"imports,omitempty"`
}

TypeReplace replaces a column type with something else

func ConvertTypeReplace

func ConvertTypeReplace(i interface{}) []TypeReplace

ConvertTypeReplace is necessary because viper

Jump to

Keyboard shortcuts

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