ast

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package ast provides types and logic for building Go ASTs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectImports

func CollectImports(typeInfos []TypeInfo) map[string]string

CollectImports gathers all unique imports from type information

func ExportedIdentifier

func ExportedIdentifier(raw string) string

ExportedIdentifier converts raw input into a public Go identifier.

func FileName

func FileName(raw string) string

FileName converts the raw name into a snake_case file name segment.

func UnexportedIdentifier

func UnexportedIdentifier(raw string) string

UnexportedIdentifier converts raw input into a private Go identifier.

func UniqueName

func UniqueName(base string, used map[string]int) (string, error)

UniqueName ensures returned identifier does not collide with previous values.

Types

type Builder

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

Builder constructs Go AST files for code generation outputs.

func New

func New(options Options) *Builder

New returns a builder configured with the provided options.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, catalog *model.Catalog, analyses []analyzer.Result) ([]File, error)

Build produces the Go AST files for the provided catalog and analyses.

type File

type File struct {
	Path string
	Node *goast.File
	Raw  []byte
}

File represents an AST file ready for rendering.

type Options

type Options struct {
	Package             string
	EmitJSONTags        bool
	EmitEmptySlices     bool
	EmitPointersForNull bool
	Prepared            PreparedOptions
	TypeResolver        *TypeResolver
}

Options configures the AST builder.

type PreparedOptions

type PreparedOptions struct {
	Enabled     bool
	EmitMetrics bool
	ThreadSafe  bool
}

PreparedOptions captures prepared-query generation toggles.

type TypeInfo

type TypeInfo struct {
	GoType      string
	UsesSQLNull bool
	Import      string // For custom types
	Package     string // For custom types
}

TypeInfo describes a resolved Go type.

type TypeResolver

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

TypeResolver handles mapping between SQL types and Go types.

func NewTypeResolver

func NewTypeResolver(transformer *transform.Transformer) *TypeResolver

NewTypeResolver creates a new TypeResolver with optional custom type support.

func NewTypeResolverFull

func NewTypeResolverFull(transformer *transform.Transformer, database config.Database, emitPointersForNull bool) *TypeResolver

NewTypeResolverFull creates a TypeResolver with all options.

func NewTypeResolverWithDatabase

func NewTypeResolverWithDatabase(transformer *transform.Transformer, database config.Database) *TypeResolver

NewTypeResolverWithDatabase creates a TypeResolver for a specific database.

func NewTypeResolverWithOptions

func NewTypeResolverWithOptions(transformer *transform.Transformer, emitPointersForNull bool) *TypeResolver

NewTypeResolverWithOptions creates a TypeResolver with all options configured.

func (*TypeResolver) GetRequiredImports

func (r *TypeResolver) GetRequiredImports() map[string]string

GetRequiredImports returns the imports needed for the resolved types.

func (*TypeResolver) GetSemanticMapper

func (r *TypeResolver) GetSemanticMapper() *types.SQLiteMapper

GetSemanticMapper returns the semantic type mapper for the current database.

func (*TypeResolver) Map

func (r *TypeResolver) Map(sqlType string, nullable bool) types.SemanticType

Map implements the types.Mapper interface for semantic type mapping.

func (*TypeResolver) ResolveType

func (r *TypeResolver) ResolveType(typeOrSQLType string, nullable bool) TypeInfo

ResolveType determines the Go type for a given SQL type or existing Go type.

Jump to

Keyboard shortcuts

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