gen

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowedFieldByType

func AllowedFieldByType(expr ast.Expr, pkgAlias string, imports []Import, filePath string) bool

AllowedFieldByType returns true if the field type should be treated as a simple, allowed column type. Rules: - Primitive numbers, bool, string - time.Time, []byte - Any named type that implements one of the allowed interfaces

func ImplementsAllowedInterfaces

func ImplementsAllowedInterfaces(typ types.Type) bool

ImplementsAllowedInterfaces reports whether typ or *typ implements any allowed interface.

func New

func New() *cobra.Command

func RenderSQLTemplate

func RenderSQLTemplate(tmpl string) (string, error)

RenderSQLTemplate parses the template string and returns Go code or an error.

func ResolveTypeFromExpr

func ResolveTypeFromExpr(expr ast.Expr, imports []Import, filePath string, preferAlias string) types.Type

ResolveTypeFromExpr attempts to resolve a types.Type for a field's AST expression. - Supports selector expressions (pkg.Type) - Supports identifiers from the current package (exported) - Ignores basic built-in types (lowercase idents) - Follows one level of pointers

Types

type ExtractedSQL

type ExtractedSQL struct {
	Raw    string
	Where  string
	Select string
}

type Field

type Field struct {
	Name        string
	DBName      string
	GoType      string
	GoTypeAlias string
	Tag         string
	// contains filtered or unexported fields
}

func (Field) Type

func (f Field) Type() string

Type returns the field type string for template generation

func (Field) Value

func (f Field) Value() string

Value returns the field value string with column name for template generation

type File

type File struct {
	Package    string
	Imports    []Import
	Interfaces []Interface
	Structs    []Struct
	Config     *genconfig.Config
	// contains filtered or unexported fields
}

func (*File) Visit

func (p *File) Visit(n ast.Node) (w ast.Visitor)

Visit implements ast.Visitor to traverse AST nodes and extract imports, interfaces, and structs

type ForNode

type ForNode struct {
	Expr string
	Body []Node
}

ForNode for {{for expr}}.

func (*ForNode) Emit

func (fn *ForNode) Emit(indent, target string, withPrefix bool) string

type FuncNode

type FuncNode struct {
	Name string
	Body []Node
}

FuncNode for {{where}} / {{set}} blocks.

func (*FuncNode) Emit

func (f *FuncNode) Emit(indent, target string, withPrefix bool) string

type Generator

type Generator struct {
	Files map[string]*File
	// contains filtered or unexported fields
}

func (*Generator) Gen

func (g *Generator) Gen() error

Gen generates code files from processed AST data

func (*Generator) Process

func (g *Generator) Process(input string) error

Process processes input files or directories and generates code

type IfBranch

type IfBranch struct {
	Cond string
	Body []Node
}

IfBranch holds one condition + body.

type IfNode

type IfNode struct {
	Branches []IfBranch
	ElseBody []Node
}

IfNode can have multiple branches (if, else if, else if, ...), plus an optional else.

func (*IfNode) Emit

func (in *IfNode) Emit(indent, target string, withPrefix bool) string

type Import

type Import struct {
	Name string
	Path string
}

func (Import) ImportPath

func (p Import) ImportPath() string

ImportPath returns formatted import path string for template generation

type Interface

type Interface struct {
	Name      string
	IfaceName string
	Doc       string
	Methods   []*Method
}

type Method

type Method struct {
	Name      string
	Doc       string
	SQL       ExtractedSQL
	Params    []Param
	Result    []Param
	Interface Interface
}

func (Method) Body

func (m Method) Body() string

Body generates the method body code for templates

func (Method) ParamsString

func (m Method) ParamsString() string

ParamsString formats method parameters as a string for code generation

func (Method) ResultString

func (m Method) ResultString() string

ResultString formats method return values as a string for code generation

type Node

type Node interface {
	Emit(indent, target string, withPrefix bool) string
}

Node is the interface that all AST nodes implement.

type Param

type Param struct {
	Name string
	Type string
}

func (Param) GoFullType

func (p Param) GoFullType() string

GoFullType returns the complete Go type string for a parameter

type Struct

type Struct struct {
	Name   string
	Doc    string
	Fields []Field
}

type TextNode

type TextNode struct {
	Text string
}

TextNode holds plain text.

func (*TextNode) Emit

func (t *TextNode) Emit(indent, target string, withPrefix bool) string

Source Files

  • gen.go
  • generator.go
  • sqlparser.go
  • template.go
  • utils.go

Jump to

Keyboard shortcuts

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