generate

package
v0.0.0-...-aa61c75 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TypesMap = map[string]TypeConf{
	"int":           {"qb.Int()", "0"},
	"uint":          {"qb.Int().Unsigned()", "0"},
	"int64":         {"qb.BigInt()", "0"},
	"uint64":        {"qb.BigInt().Unsigned()", "0"},
	"string":        {"qb.Varchar()", `""`},
	"*string":       {"qb.Varchar()", "nil"},
	"bool":          {"qb.Boolean()", "false"},
	"time.Time":     {"qb.Timestamp()", "(time.Time{})"},
	"*time.Time":    {"qb.Timestamp()", "nil"},
	"uuid.UUID":     {"qb.UUID()", "(uuid.UUID{})"},
	"uuid.NullUUID": {"qb.UUID()", "(uuid.NullUUID{})"},
}

TypesMap associate column types and empty values to go types. It is used to guess the column type at generation time.

Functions

func ProcessFile

func ProcessFile(logger *log.Logger, path string, file string, pack string, output string, format bool) error

ProcessFile processes a go file and generates mapper and mappedstruct interfaces implementations for the yago structs.

func ToDBName

func ToDBName(name string) string

ToDBName convert string to db name

Types

type ColumnTags

type ColumnTags struct {
	ColumnName    string
	Type          string
	PrimaryKey    bool
	AutoIncrement bool
	Null          bool
	NotNull       bool
	ForeignKeys   []string
	Indexes       []string
	UniqueIndexes []string
	TextMarshaled bool
}

ColumnTags contains tags set on the fields

type FKData

type FKData struct {
	Column    *FieldData
	RefTable  *StructData
	RefColumn *FieldData
	OnUpdate  string
	OnDelete  string
}

FKData describe a foreign key

type FieldData

type FieldData struct {
	Tags            ColumnTags
	Name            string
	NameConst       string
	Type            string
	EmptyValue      string
	ColumnName      string
	ColumnType      string
	ColumnModifiers string
	ColumnNameConst string
	FromEmbedded    bool
}

FieldData describes a field to be mapped

type FileData

type FileData struct {
	Package   string
	Imports   map[string]bool
	HasTables bool
}

FileData contains top-level infos for templates

type StructData

type StructData struct {
	Imported          bool
	Name              string
	PrivateBasename   string
	TableName         string
	Fields            []FieldData
	PKeyFields        []*FieldData
	AutoIncrementPKey *FieldData

	Indexes       map[string][]int
	UniqueIndexes map[string][]int
	ForeignKeys   []FKData

	NoTable bool
	Embed   []string

	File FileData
}

StructData describes a struct to be mapped

func ParseDir

func ParseDir(path string) ([]*StructData, error)

ParseDir parses all the go files in a directory and returns their mapped structs

func ParseFile

func ParseFile(path string) ([]*StructData, error)

ParseFile parses a file and returns found structs that should be mapped

type TypeConf

type TypeConf struct {
	ColumnName string
	EmptyValue string
}

TypeConf contains column type and empty value of a go type

Jump to

Keyboard shortcuts

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