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

Function Generate

internal/cmd/generate.go:134–169  ·  view source on GitHub ↗
(ctx context.Context, dir, filename string, o *Options)

Source from the content-addressed store, hash-verified

132}
133
134func Generate(ctx context.Context, dir, filename string, o *Options) (map[string]string, error) {
135 e := o.Env
136 stderr := o.Stderr
137
138 configPath, conf, err := o.ReadConfig(dir, filename)
139 if err != nil {
140 return nil, err
141 }
142
143 base := filepath.Base(configPath)
144 if err := config.Validate(conf); err != nil {
145 fmt.Fprintf(stderr, "error validating %s: %s\n", base, err)
146 return nil, err
147 }
148
149 if err := e.Validate(conf); err != nil {
150 fmt.Fprintf(stderr, "error validating %s: %s\n", base, err)
151 return nil, err
152 }
153
154 // Comment on why these two methods exist
155 if conf.Cloud.Project != "" && e.Remote && !e.NoRemote {
156 return remoteGenerate(ctx, configPath, conf, dir, stderr)
157 }
158
159 g := &generator{
160 dir: dir,
161 output: map[string]string{},
162 }
163
164 if err := processQuerySets(ctx, g, conf, dir, o); err != nil {
165 return nil, err
166 }
167
168 return g.output, nil
169}
170
171type generator struct {
172 m sync.Mutex

Callers 6

TestExamplesFunction · 0.92
BenchmarkExamplesFunction · 0.92
TestReplayFunction · 0.92
BenchmarkReplayFunction · 0.92
DiffFunction · 0.70
cmd.goFile · 0.70

Calls 5

ValidateFunction · 0.92
remoteGenerateFunction · 0.85
processQuerySetsFunction · 0.85
ReadConfigMethod · 0.80
ValidateMethod · 0.45

Tested by 4

TestExamplesFunction · 0.74
BenchmarkExamplesFunction · 0.74
TestReplayFunction · 0.74
BenchmarkReplayFunction · 0.74