codegen

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package codegen orchestrates the generation of Go code from SQL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 File

type File struct {
	Path    string
	Content []byte
}

File represents a generated source file.

type Generator

type Generator interface {
	Generate(ctx context.Context, catalog *model.Catalog, analyses []analyzer.Result) ([]File, error)
}

Generator produces Go code from parsed schemas and queries.

func New

func New(opts Options) Generator

New creates a new Generator.

type GeneratorFactory

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

GeneratorFactory creates language-specific generators.

func NewGeneratorFactory

func NewGeneratorFactory(opts Options) *GeneratorFactory

NewGeneratorFactory creates a new generator factory.

func (*GeneratorFactory) Create

func (f *GeneratorFactory) Create(lang config.Language) (Generator, error)

Create returns a generator for the specified language.

type Options

type Options struct {
	Package             string
	Database            config.Database
	EmitJSONTags        bool
	EmitEmptySlices     bool
	EmitPointersForNull bool
	// G7 emit_* options. Each defaults to the pre-G7 behavior (see ast.Options).
	EmitDBTags               bool
	JSONTagsCaseStyle        string
	EmitResultStructPointers bool
	EmitParamsStructPointers bool
	// SuppressInterface skips the Querier interface (querier.gen.go). The zero
	// value (false) emits it, matching db-catalyst's always-emit default, so a
	// bare codegen.Options{} reproduces the pre-G7 output. emit_interface = false
	// sets this to true via the pipeline.
	SuppressInterface bool
	// Initialisms renders SQL-derived Go identifiers with the golint/sqlc
	// initialism table (user_id → UserID). Default false keeps legacy casing.
	Initialisms bool
	// Rename maps exact SQL names to exported Go identifiers, winning over
	// Initialisms and applying regardless of that flag.
	Rename          map[string]string
	Prepared        PreparedOptions
	CustomTypes     []config.CustomTypeMapping
	ColumnOverrides []config.ColumnOverride
	SQL             SQLOptions
	// ModelsPackage, when non-empty, emits the table-model structs into a
	// separate sub-package of this name (and sub-directory under Out).
	ModelsPackage string
	// ModelsImport is the full import path of the models sub-package, used by
	// the main package files to reference the split model types.
	ModelsImport string
}

Options configures the Generator.

type PreparedOptions

type PreparedOptions struct {
	Enabled     bool
	EmitMetrics bool
	ThreadSafe  bool
}

PreparedOptions configures prepared statement generation.

type SQLOptions

type SQLOptions struct {
	Enabled         bool
	Dialect         string
	EmitIFNotExists bool
}

SQLOptions configures SQL schema output.

Directories

Path Synopsis
Package ast provides types and logic for building Go ASTs.
Package ast provides types and logic for building Go ASTs.
Package render formats and writes generated Go code.
Package render formats and writes generated Go code.
Package rust generates Rust code using text templates.
Package rust generates Rust code using text templates.
Package sql generates SQL schema definitions from a database catalog.
Package sql generates SQL schema definitions from a database catalog.
Package typescript generates TypeScript code using text templates.
Package typescript generates TypeScript code using text templates.

Jump to

Keyboard shortcuts

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