sqlfix

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: 16 Imported by: 0

Documentation

Overview

Package sqlfix implements tools for automated SQL rewrites and migration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddedAlias

type AddedAlias struct {
	QueryName   string
	ColumnIndex int
	Alias       string
}

AddedAlias records an alias added to a query column.

type AliasGenerator

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

AliasGenerator generates unique column aliases for SQL queries.

func NewAliasGenerator

func NewAliasGenerator() *AliasGenerator

NewAliasGenerator creates a new AliasGenerator.

func (*AliasGenerator) Next

func (g *AliasGenerator) Next(expr string) string

Next generates a deterministic, unique alias for the given expression.

func (*AliasGenerator) Reserve

func (g *AliasGenerator) Reserve(alias string)

Reserve marks an alias as already used to prevent collisions.

type Report

type Report struct {
	Path          string
	Added         []AddedAlias
	Skipped       []SkippedAlias
	Warnings      []string
	ExpandedStars int
}

Report contains the results of a sqlfix run on a single file.

func (Report) Changed

func (r Report) Changed() bool

Changed returns true if any changes were made to the file.

type Runner

type Runner struct {
	Logger *slog.Logger
	DryRun bool
	// contains filtered or unexported fields
}

Runner executes the sqlfix logic on a set of files.

func NewRunner

func NewRunner() *Runner

NewRunner creates a new sqlfix Runner.

func (*Runner) CatalogWarnings

func (r *Runner) CatalogWarnings() []string

CatalogWarnings returns any warnings encountered during catalog loading.

func (*Runner) Rewrite

func (r *Runner) Rewrite(ctx context.Context, paths []string) ([]Report, error)

Rewrite processes the given file paths and applies necessary fixes.

func (*Runner) SetCatalog

func (r *Runner) SetCatalog(catalog *model.Catalog, warnings []string)

SetCatalog sets the schema catalog used for star expansion and validation.

type SchemaCatalog

type SchemaCatalog struct {
	Catalog  *model.Catalog
	Warnings []string
}

SchemaCatalog holds the parsed database schema and any warnings.

func LoadSchemaCatalog

func LoadSchemaCatalog(paths []string, readFile func(string) ([]byte, error)) (SchemaCatalog, error)

LoadSchemaCatalog loads and parses schema files from the given paths.

type SkippedAlias

type SkippedAlias struct {
	QueryName string
	Expr      string
	Reason    string
}

SkippedAlias records a column that could not be aliased.

Directories

Path Synopsis
Package overrides handles conversion of sqlc configuration overrides to db-catalyst format.
Package overrides handles conversion of sqlc configuration overrides to db-catalyst format.
Package sqlcconfig parses sqlc configuration files.
Package sqlcconfig parses sqlc configuration files.

Jump to

Keyboard shortcuts

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