SQLC Config Discovery
Overview
Section titled “Overview”gogenfilter discovers SQLC configuration files and extracts output directories, so you don’t have to hardcode paths. It supports both v1 and v2 config formats, including plugin-based codegen and JSON output.
Supported Config Formats
Section titled “Supported Config Formats”sqlc.yamlandsqlc.yml- Version 1 (
version: "1") and Version 2 (version: "2")
V2 Format
Section titled “V2 Format”version: "2"sql: - engine: "postgresql" schema: "queries/" queries: "queries/" gen: go: package: "db" out: "gen/db" # Go output directory json: out: "gen/json" # JSON output directory codegen: - plugin: "go-structs" out: "gen/structs" # Plugin output directoryAll three output directory sources are extracted:
| Source | Field |
|---|---|
| Go codegen | sql[].gen.go.out |
| JSON output | sql[].gen.json.out |
| Plugin codegen | sql[].codegen[].out |
V1 Format
Section titled “V1 Format”version: "1"packages: - name: "db" path: "gen/db" # output directory engine: "postgresql" schema: "queries/" queries: "queries/"V1 configs use packages[].path as the output directory, which is automatically mapped.
Find Configs
Section titled “Find Configs”FindSQLCConfigs searches the provided paths for sqlc.yaml / sqlc.yml. It also searches parent directories (up to 10 levels up) for configs that may live above the query directory.
configs, err := gogenfilter.FindSQLCConfigs([]string{"./..."})if err != nil { log.Fatal(err)}
for path, root := range configs { fmt.Printf("Config: %s (root: %s)\n", path, root)}Filesystem Variant
Section titled “Filesystem Variant”FindSQLCConfigsFS is the fs.FS-compatible version. It does not search parent directories — use this for testing or custom filesystems:
configs, err := gogenfilter.FindSQLCConfigsFS(fsys, []string{"."})Get Output Directories
Section titled “Get Output Directories”GetSQLOutputDirs reads config files and extracts output directories:
dirs, err := gogenfilter.GetSQLOutputDirs([]string{"."})if err != nil { log.Fatal(err)}
for _, dir := range dirs { fmt.Printf("Output: %s\n", dir)}Filesystem Variant
Section titled “Filesystem Variant”dirs, err := gogenfilter.GetSQLOutputDirsFS(fsys, []string{"."})Use Case
Section titled “Use Case”Combine config discovery with include patterns for precise scoping:
dirs, _ := gogenfilter.GetSQLOutputDirs([]string{"."})
includePatterns := make([]string, len(dirs))for i, dir := range dirs { includePatterns[i] = dir + "/**"}
opts, err := gogenfilter.WithFilterOptions(gogenfilter.FilterSQLC)if err != nil { panic(err)}includeConfig := gogenfilter.WithIncludePatterns(includePatterns...)f, err := gogenfilter.NewFilter(opts, includeConfig)if err != nil { panic(err)}Implementation Details
Section titled “Implementation Details”The parser uses github.com/go-faster/yaml — a 2–3x faster, actively maintained fork of go-yaml/yaml. The config version is detected first, then dispatched to v1 or v2 parsing logic. Unsupported versions return a parse error. See the Known Limitations page for documented tradeoffs.