MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / codegen

Function codegen

internal/cmd/generate.go:336–413  ·  view source on GitHub ↗
(ctx context.Context, combo config.CombinedSettings, sql OutputPair, result *compiler.Result)

Source from the content-addressed store, hash-verified

334}
335
336func codegen(ctx context.Context, combo config.CombinedSettings, sql OutputPair, result *compiler.Result) (string, *plugin.GenerateResponse, error) {
337 defer trace.StartRegion(ctx, "codegen").End()
338 req := codeGenRequest(result, combo)
339 var handler grpc.ClientConnInterface
340 var out string
341 switch {
342 case sql.Plugin != nil:
343 out = sql.Plugin.Out
344 plug, err := findPlugin(combo.Global, sql.Plugin.Plugin)
345 if err != nil {
346 return "", nil, fmt.Errorf("plugin not found: %s", err)
347 }
348
349 switch {
350 case plug.Process != nil:
351 handler = &process.Runner{
352 Cmd: plug.Process.Cmd,
353 Env: plug.Env,
354 Format: plug.Process.Format,
355 }
356 case plug.WASM != nil:
357 handler = &wasm.Runner{
358 URL: plug.WASM.URL,
359 SHA256: plug.WASM.SHA256,
360 Env: plug.Env,
361 }
362 default:
363 return "", nil, fmt.Errorf("unsupported plugin type")
364 }
365
366 opts, err := convert.YAMLtoJSON(sql.Plugin.Options)
367 if err != nil {
368 return "", nil, fmt.Errorf("invalid plugin options: %w", err)
369 }
370 req.PluginOptions = opts
371
372 global, found := combo.Global.Options[plug.Name]
373 if found {
374 opts, err := convert.YAMLtoJSON(global)
375 if err != nil {
376 return "", nil, fmt.Errorf("invalid global options: %w", err)
377 }
378 req.GlobalOptions = opts
379 }
380
381 case sql.Gen.Go != nil:
382 out = combo.Go.Out
383 handler = ext.HandleFunc(golang.Generate)
384 opts, err := json.Marshal(sql.Gen.Go)
385 if err != nil {
386 return "", nil, fmt.Errorf("opts marshal failed: %w", err)
387 }
388 req.PluginOptions = opts
389
390 if combo.Global.Overrides.Go != nil {
391 opts, err := json.Marshal(combo.Global.Overrides.Go)
392 if err != nil {
393 return "", nil, fmt.Errorf("opts marshal failed: %w", err)

Callers 1

ProcessResultMethod · 0.85

Calls 6

GenerateMethod · 0.95
YAMLtoJSONFunction · 0.92
HandleFuncFunction · 0.92
NewCodegenServiceClientFunction · 0.92
codeGenRequestFunction · 0.85
findPluginFunction · 0.85

Tested by

no test coverage detected