codegen

package
v1.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagOptionAutoIncrement = "auto_increment"
	TagOptionBinary        = "binary"
	TagOptionPKAlias       = "pk"
	TagOptionPK            = "primary_key"
	TagOptionFKAlias       = "fk"
	TagOptionFK            = "foreign_key"
	TagOptionUnsigned      = "unsigned"
	TagOptionSize          = "size"
	TagOptionDataType      = "data_type"
	TagOptionEncode        = "encode"
	TagOptionDecode        = "decode"
	TagOptionUnique        = "unique"
	TagOptionIndex         = "index"
)
View Source
const (
	SnakeCase  naming = "snake_case"
	CamelCase  naming = "camelCase"
	PascalCase naming = "PascalCase"
)
View Source
const (
	DefaultConfigFile    = "sqlgen.yml"
	DefaultGeneratedFile = "generated.go"
	DefaultStructTag     = "sql"
)

Variables

This section is empty.

Functions

func Generate

func Generate(c *Config) error

func Init

func Init(cfg *Config) error

Types

type Config

type Config struct {
	Source []string  `yaml:"src"`
	Driver SqlDriver `yaml:"driver"`
	// The possibly values of naming convention are
	// 	SnakeCase
	//	PascalCase
	// 	CamelCase
	NamingConvention naming `yaml:"naming_convention,omitempty"`
	Tag              string `yaml:"struct_tag,omitempty"`
	// Whether to quote the table name or column name
	QuoteIdentifier bool                `yaml:"quote_identifier"`
	ReadOnly        bool                `yaml:"read_only"`
	Strict          *bool               `yaml:"strict,omitempty"`
	Exec            ExecConfig          `yaml:"exec"`
	Getter          GetterConfig        `yaml:"getter"`
	Migration       *MigrationConfig    `yaml:"migration"`
	Database        *DatabaseConfig     `yaml:"database"`
	OmitGetters     bool                `yaml:"omit_getters,omitempty"`
	SourceMap       bool                `yaml:"source_map"`
	SkipHeader      bool                `yaml:"skip_header"`
	SkipModTidy     bool                `yaml:"skip_mod_tidy"`
	DataTypes       map[string]DataType `yaml:"data_types"`
}

func DefaultConfig

func DefaultConfig() *Config

func LoadConfigFrom

func LoadConfigFrom(src string) (*Config, error)

func (*Config) Init

func (c *Config) Init()

func (*Config) Merge

func (c *Config) Merge(mapCfg *Config) *Config

func (Config) RenameFunc

func (c Config) RenameFunc() func(string) string

type DataType

type DataType struct {
	DataType   string `yaml:"data_type"`
	Scanner    string `yaml:"scan"`
	SQLScanner string `yaml:"sql_scan"`
	Valuer     string `yaml:"value"`
	SQLValuer  string `yaml:"sql_value"`
}

type DatabaseConfig

type DatabaseConfig struct {
	Package  string                  `yaml:"package"`
	Dir      string                  `yaml:"dir"`
	Filename string                  `yaml:"filename"`
	Operator *DatabaseOperatorConfig `yaml:"operator"`
}

type DatabaseOperatorConfig

type DatabaseOperatorConfig struct {
	Package  string `yaml:"package"`
	Dir      string `yaml:"dir"`
	Filename string `yaml:"filename"`
}

type EmptyMatcher

type EmptyMatcher struct{}

func (*EmptyMatcher) Match

func (*EmptyMatcher) Match(v string) bool

type ExecConfig

type ExecConfig struct {
	// Skip `generated.go` file being generated if the input has no matching struct
	SkipEmpty bool `yaml:"skip_empty"`
	// Declare the name of generated go file. Default is `generated.go`
	Filename string `yaml:"filename"`
}

type Expr

type Expr string

Currently this template is support following expression:

  • {{.}} - current go path
  • {{goPath}} - go path
  • {{addrOfGoPath}} - address of go path
  • {{len}} - go array size

func (Expr) Format

func (e Expr) Format(pkg *Package, args ...ExprParams) string

type ExprParams

type ExprParams struct {
	// You may pass `&v.Path` or `v.Path` or any relevant go path,
	// we will check whether it's addr of the go path
	GoPath string
	IsPtr  bool
	Len    int64
	Type   types.Type
}

type FileMatcher

type FileMatcher map[string]struct{}

func (FileMatcher) Match

func (f FileMatcher) Match(v string) bool

type Generator

type Generator struct {
	*bytes.Buffer
	// contains filtered or unexported fields
}

func (*Generator) L

func (g *Generator) L(str ...any) error

func (*Generator) LogError

func (g *Generator) LogError(err error)

func (*Generator) Quote

func (g *Generator) Quote(str string) string

func (*Generator) QuoteIdentifier

func (g *Generator) QuoteIdentifier(str string) string

type GetterConfig

type GetterConfig struct {
	Prefix string `yaml:"prefix"`
}

type Matcher

type Matcher interface {
	Match(v string) bool
}

type MigrationConfig

type MigrationConfig struct {
	DSN      string `yaml:"dsn"`
	Package  string `yaml:"package"`
	Dir      string `yaml:"dir"`
	Filename string `yaml:"filename"`
}

type Package

type Package struct {
	// contains filtered or unexported fields
}

func NewPackage

func NewPackage(path, name string) *Package

func (*Package) Import

func (p *Package) Import(pkg *types.Package) (*types.Package, bool)

func (Package) Name

func (p Package) Name() string

func (Package) PkgPath

func (p Package) PkgPath() string

type RegexMatcher

type RegexMatcher struct {
	*regexp.Regexp
}

func (*RegexMatcher) Match

func (r *RegexMatcher) Match(v string) bool

type SqlDriver

type SqlDriver string
const (
	MySQL       SqlDriver = "mysql"
	Postgres    SqlDriver = "postgres"
	Sqlite      SqlDriver = "sqlite"
	MSSqlServer SqlDriver = "mssql"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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