base

package
v0.0.0-...-70569e3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Conn is connection string (-c) basic flag
	Conn = "conn"

	// Output is output filename (-o) basic flag
	Output = "output"

	// Tables is basic flag (-t) for tables to generate
	Tables = "tables"

	// FollowFKs is basic flag (-f) for generate foreign keys models for selected tables
	FollowFKs = "follow-fk"

	// Package for model files
	Pkg = "pkg"
)

Variables

This section is empty.

Functions

func AddFlags

func AddFlags(command *cobra.Command)

AddFlags adds basic flags to command

func CreateCommand

func CreateCommand(name, description string, generator Gen) *cobra.Command

CreateCommand creates cobra command

func ReadFlags

func ReadFlags(command *cobra.Command, o *Options) (err error)

ReadFlags reads basic flags from command

Types

type Gen

type Gen interface {
	AddFlags(command *cobra.Command)
	ReadFlags(command *cobra.Command) error

	Generate() error
}

Gen is interface for all generators

type Generator

type Generator struct {
	bungen.Bungen
	Name string
}

Generator is base generator used in other generators

func NewGenerator

func NewGenerator(url string, n string) Generator

NewGenerator creates generator

func (Generator) Generate

func (g Generator) Generate(tables []string, followFKs, useSQLNulls bool, output, tmpl string, packer Packer, customTypes model.CustomTypeMapping) error

Generate runs whole generation process

func (Generator) GenerateFromEntities

func (g Generator) GenerateFromEntities(entities []model.Entity, output, tmpl string, packer Packer) error

type Options

type Options struct {
	// URL connection string
	URL string

	// Output file path
	Output string

	// List of Tables to generate
	// Default []string{"public.*"}
	Tables []string

	// Generate model for foreign keys,
	// even if Tables not listed in Tables param
	// will not generate fks if schema not listed
	FollowFKs bool
	// Package sets package name for model
	// Works only with SchemaPackage = false
	Package string

	// Do not replace primary key name to ID
	KeepPK bool

	// Soft delete column
	SoftDelete string

	// use sql.Null... instead of pointers
	UseSQLNulls bool

	// Do not generate alias tag
	NoAlias bool

	// Do not generate discard_unknown_columns tag
	NoDiscard bool

	// Override type for json/jsonb
	JSONTypes map[string]string

	// Add json tag to models
	AddJSONTag bool

	// Generate basic ORM queries
	WithORM bool
	// Generate Search queries
	WithSearch bool
	// Generate Vallidation functions
	WithValidation bool
	// Strict types in filters
	Relaxed bool

	// Struct name for ORM queries. Works only when GenORM == true
	DBWrapName string
	// Custom types goes here
	CustomTypes model.CustomTypeMapping
}

Options is common options for all generators

func (*Options) Def

func (o *Options) Def()

Def sets default options if empty

type Packer

type Packer func(entities []model.Entity) (interface{}, error)

Packer is a function that compile entities to package

Jump to

Keyboard shortcuts

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