gen

package
v0.15.4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: MIT Imports: 24 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ModelTemplates, _       = fs.Sub(templates, "templates/models")
	FactoryTemplates, _     = fs.Sub(templates, "templates/factory")
	MySQLModelTemplates, _  = fs.Sub(mysqlTemplates, "bobgen-mysql/templates/models")
	PrismaModelTemplates, _ = fs.Sub(prismaTemplates, "bobgen-prisma/templates/models")
)

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 `yaml:"tables,omitempty" toml:"tables,omitempty" json:"tables,omitempty"`
}

Aliases defines aliases for the generation run

func (Aliases) Table

func (a Aliases) Table(table string) TableAlias

Table gets a table alias, panics if not found.

type Config

type Config struct {
	// Additional struct tags to generate (including json, yaml and toml)
	Tags []string `yaml:"tags"`
	// Disable generating factory for models.
	NoFactory bool `yaml:"no_factory"`
	// Disable generated go test files
	NoTests bool `yaml:"no_tests"`
	// Disable back referencing in the loaded relationship structs
	NoBackReferencing bool `yaml:"no_back_referencing"`
	// Delete the output folder (rm -rf) before generation to ensure sanity
	Wipe bool `yaml:"wipe"`
	// Decides the casing for go structure tag names. camel, title or snake (default snake)
	StructTagCasing string `yaml:"struct_tag_casing"`
	// Relationship struct tag name
	RelationTag string `yaml:"relation_tag"`
	// List of column names that should have tags values set to '-' (ignored during parsing)
	TagIgnore []string `yaml:"tag_ignore"`

	Aliases       Aliases       `yaml:"aliases"`
	Replacements  []Replace     `yaml:"replacements"`
	Relationships relationships `yaml:"relationships"`
	Inflections   Inflections   `yaml:"inflections"`

	// Customize the generator name in the top level comment of generated files
	// >>   Code generated by **GENERATOR NAME**. DO NOT EDIT.
	// defaults to "BobGen [plugin] [version]"
	Generator string `yaml:"generator" toml:"generator" json:"generator"`
}

Config for the running of the commands

type Importer

type Importer map[string]struct{}

func (Importer) Import

func (i Importer) Import(pkgs ...string) string

To be used inside templates to record an import. Always returns an empty string

func (Importer) ImportList

func (i Importer) ImportList(list importers.List) string

func (Importer) ToList

func (i Importer) ToList() importers.List

type Inflections

type Inflections struct {
	Plural        map[string]string `yaml:"plural"`
	PluralExact   map[string]string `yaml:"plural_exact"`
	Singular      map[string]string `yaml:"singular"`
	SingularExact map[string]string `yaml:"singular_exact"`
	Irregular     map[string]string `yaml:"irregular"`
}

type Output

type Output struct {
	PkgName   string  `yaml:"pkg_name" toml:"pkg_name" json:"pkg_name"`
	OutFolder string  `yaml:"out_folder" toml:"out_folder" json:"out_folder"`
	Templates []fs.FS `yaml:"-" toml:"-" json:"-"`
	// contains filtered or unexported fields
}

type Replace

type Replace struct {
	Tables  []string       `yaml:"tables" toml:"tables" json:"tables"`
	Match   drivers.Column `yaml:"match" toml:"match" json:"match"`
	Replace drivers.Column `yaml:"replace" toml:"replace" json:"replace"`
}

Replace replaces a column type with something else

type State

type State[T any] struct {
	Config              *Config
	Dialect             string
	Outputs             []*Output
	ModelsPkg           string
	CustomTemplateFuncs template.FuncMap
	// contains filtered or unexported fields
}

State holds the global data needed by most pieces to run

func (*State[T]) Run

func (s *State[T]) Run(ctx context.Context, driver drivers.Interface[T]) error

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

type TableAlias

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

	Columns       map[string]string `yaml:"columns,omitempty" toml:"columns,omitempty" json:"columns,omitempty"`
	Relationships map[string]string `yaml:"relationships,omitempty" 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) string

Relationship looks up a relationship, panics if not found.

Directories

Path Synopsis
Package drivers talks to various database backends and retrieves table, column, type, and foreign key information
Package drivers talks to various database backends and retrieves table, column, type, and foreign key information
Package importers helps with dynamic imports for templating
Package importers helps with dynamic imports for templating

Jump to

Keyboard shortcuts

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