MCPcopy
hub / github.com/sqlc-dev/sqlc / processQuerySets

Function processQuerySets

internal/cmd/process.go:55–134  ·  view source on GitHub ↗
(ctx context.Context, rp ResultProcessor, conf *config.Config, dir string, o *Options)

Source from the content-addressed store, hash-verified

53}
54
55func processQuerySets(ctx context.Context, rp ResultProcessor, conf *config.Config, dir string, o *Options) error {
56 stderr := o.Stderr
57
58 errored := false
59
60 pairs := rp.Pairs(ctx, conf)
61 grp, gctx := errgroup.WithContext(ctx)
62 grp.SetLimit(runtime.GOMAXPROCS(0))
63
64 stderrs := make([]bytes.Buffer, len(pairs))
65
66 for i, pair := range pairs {
67 sql := pair
68 errout := &stderrs[i]
69
70 grp.Go(func() error {
71 combo := config.Combine(*conf, sql.SQL)
72 if sql.Plugin != nil {
73 combo.Codegen = *sql.Plugin
74 }
75
76 // TODO: This feels like a hack that will bite us later
77 joined := make([]string, 0, len(sql.Schema))
78 for _, s := range sql.Schema {
79 joined = append(joined, filepath.Join(dir, s))
80 }
81 sql.Schema = joined
82
83 joined = make([]string, 0, len(sql.Queries))
84 for _, q := range sql.Queries {
85 joined = append(joined, filepath.Join(dir, q))
86 }
87 sql.Queries = joined
88
89 var name, lang string
90 parseOpts := opts.Parser{
91 Debug: debug.Debug,
92 }
93
94 switch {
95 case sql.Gen.Go != nil:
96 name = combo.Go.Package
97 lang = "golang"
98
99 case sql.Plugin != nil:
100 lang = fmt.Sprintf("process:%s", sql.Plugin.Plugin)
101 name = sql.Plugin.Plugin
102 }
103
104 packageRegion := trace.StartRegion(gctx, "package")
105 trace.Logf(gctx, "", "name=%s dir=%s plugin=%s", name, dir, lang)
106
107 result, failed := parse(gctx, name, dir, sql.SQL, combo, parseOpts, errout)
108 if failed {
109 packageRegion.End()
110 errored = true
111 return nil
112 }

Callers 2

ProcessFunction · 0.85
GenerateFunction · 0.85

Calls 5

CombineFunction · 0.92
parseFunction · 0.85
PairsMethod · 0.65
ProcessResultMethod · 0.65
JoinMethod · 0.45

Tested by

no test coverage detected