qualifymodels

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(modelPath, queryGlob, modelImport string) error

Run processes SQLC-generated query files and qualifies bare model type references by prefixing them with a package alias and injecting the corresponding import. If SQLC v2+ native model qualification is detected via isSQLCModern(), it logs a message and exits without modifying any files.

Workflow:

  1. Check for native SQLC qualification support; if present, skip processing.
  2. Parse the models file at modelPath and collect all struct type names.
  3. Derive the package alias from modelImport (last path element).
  4. Glob for all query files matching queryGlob.
  5. For each file: a) Parse its AST and traverse all identifiers. b) When an identifier matches a model name and is not already part of a selector, replace it with `alias.Identifier`. c) Ensure the import for modelImport is present. d) Rewrite the file in place with `go/format`.

Parameters:

  • modelPath: Path to the Go source file defining your models.
  • queryGlob: Glob pattern to match SQLC‑generated `.sql.go` files.
  • modelImport: Import path for your external models package.

Returns:

  • error: Any error encountered while parsing, globbing, or writing files. Returns nil if native SQLC qualification is enabled or if all files are successfully processed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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