base

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 11 Imported by: 11

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"

	// Go-PG version to use
	GoPgVer = "gopg"

	// 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) (conn, output, pkg string, tables []string, followFKs bool, gopgVer int, customTypes model.CustomTypeMapping, 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 {
	genna.Genna
}

Generator is base generator used in other generators

func NewGenerator

func NewGenerator(url string) Generator

NewGenerator creates generator

func (Generator) Generate

func (g Generator) Generate(tables []string, followFKs, useSQLNulls bool, output, tmpl string, packer Packer, goPGVer int, 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

	// go-pg version
	GoPgVer int

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