Documentation
¶
Overview ¶
Package generator handles code generation for peng-managed artifacts: the per-seed sqlc.yaml that drives query.sql.go generation, the sqlc subprocess invocation, and (in a later milestone) the auto-generated seed registry.go.
All output is rooted at the parent of the seeds directory — for the default layout that means files land under peng/.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SeedDirPattern = regexp.MustCompile(`^(\d+)_([a-zA-Z][a-zA-Z0-9_]*)$`)
SeedDirPattern is the naming convention for seed subdirectories: <digits>_<identifier>. The identifier doubles as the Go package name, so it must be a valid Go identifier.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
SeedsDir string
MigrationsDir string
// SqlcConfigPath is where the generated sqlc.yaml is written.
// Defaults to <parent-of-SeedsDir>/sqlc.yaml — i.e. peng/sqlc.yaml
// when SeedsDir is the conventional peng/seeds.
SqlcConfigPath string
}
Generator orchestrates sqlc code generation for all seed packages under SeedsDir using MigrationsDir as the schema source.
func New ¶
New returns a Generator with the conventional sqlc.yaml location (a sibling of SeedsDir under its parent).
func (*Generator) Generate ¶
Generate runs the full pipeline: WriteConfig then Run. The config write is cheap and idempotent; sqlc is the expensive step.
func (*Generator) Run ¶
Run invokes `sqlc generate -f <SqlcConfigPath>`. Caller should have called WriteConfig recently so the file matches the on-disk seeds. Returns an error that includes sqlc's combined output on failure.
func (*Generator) WriteConfig ¶
WriteConfig walks SeedsDir, discovers each valid seed, and writes a sqlc.yaml at SqlcConfigPath with one `sql:` block per seed. All paths in the file are computed relative to the sqlc.yaml's own location so sqlc resolves them correctly when invoked from any cwd. Any existing file at SqlcConfigPath is overwritten.
type SeedInfo ¶
type SeedInfo struct {
Dir string // absolute or repo-relative directory path
Version string // numeric prefix
Name string // identifier suffix
PackageName string // Go package name (equal to Name)
}
SeedInfo describes one discovered seed directory.
func DiscoverSeeds ¶
DiscoverSeeds returns the seed subdirectories of seedsDir that have a query.sql file, sorted by version ascending. Directories that do not match the naming pattern or lack query.sql are skipped without error. A non-existent seedsDir returns an empty slice with no error.